Problem p03835 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <functional> // std::greater<T>()
#include <iostream>
#include <string>
#include <vector>

using namespace std;

// macro
#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for (int i = 0; i < (int)(n); i++)   // 0 ~ n-1
#define REPN(i, n) for (int i = 1; i <= (int)(n); i++) // 1 ~ n
#define DESCEND greater<int>()                         // sort 降順
#define UNIQUE(vec)                                                            \
  (vec).erase(unique(ALL((vec))), (vec).end()); // 必ずsortを行なってから

// func declaration
template <class T> void printVec(vector<T>);
template <class T> void calcVec(vector<T> &, int, char);
bool checkMultiple(vector<int> &, int);

// const
const int INF = 10000000;

/*MEMO
辞書順
abc < abcd, atcoder < atlas
*/

int main() {
  int K, S;
  cin >> K >> S;
  int count = 0;
  for (int X = K; X >= 0; --X) {
    int num = S - X;
    if (num > 0) {
      for (int Y = K; Y >= 0; --Y) {
        int num1 = num - Y;
        if (num1 > 0) {
          for (int Z = K; Z >= 0; --Z) {
            if ((num1 - Z) == 0) {
              count++;
              continue;
            }
          }
        } else if (num1 == 0) {
          count++;
          continue;
        }
      }
    } else if (num == 0) {
      count++;
      continue;
    }
  }
  cout << count << endl;

  return 0;
}

// function
template <class T> void printVec(vector<T> vec) {
  // 1要素ずつ、空白・改行なしで出力
  REP(i, vec.size()) { cout << vec.at(i); }
  cout << endl;
}

template <class T> void calcVec(vector<T> &vec, int num, char ch) {
  // vec全体への演算
  if (ch == '+') {
    REP(i, vec.size()) { vec.at(i) += num; }
  } else if (ch == '-') {
    REP(i, vec.size()) { vec.at(i) -= num; }
  } else if (ch == '*') {
    REP(i, vec.size()) { vec.at(i) *= num; }
  } else if (ch == '/') {
    REP(i, vec.size()) { vec.at(i) /= num; }
  } else if (ch == '%') {
    REP(i, vec.size()) { vec.at(i) %= num; }
  }
}

bool checkMultiple(vector<int> &vec, int num) {
  // vecの中身が、numの倍数かどうかのチェック
  int count = 0;
  REP(i, vec.size()) {
    if (vec.at(i) % num != 0)
      count++;
  }
  return (count == 0);
}


Fixed submission:
#include <algorithm>
#include <functional> // std::greater<T>()
#include <iostream>
#include <string>
#include <vector>

using namespace std;

// macro
#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for (int i = 0; i < (int)(n); i++)   // 0 ~ n-1
#define REPN(i, n) for (int i = 1; i <= (int)(n); i++) // 1 ~ n
#define DESCEND greater<int>()                         // sort 降順
#define UNIQUE(vec)                                                            \
  (vec).erase(unique(ALL((vec))), (vec).end()); // 必ずsortを行なってから

// func declaration
template <class T> void printVec(vector<T>);
template <class T> void calcVec(vector<T> &, int, char);
bool checkMultiple(vector<int> &, int);

// const
const int INF = 10000000;

/*MEMO
辞書順
abc < abcd, atcoder < atlas
*/

int main() {
  int K, S;
  cin >> K >> S;
  int count = 0;
  for (int X = 0; X <= K; ++X) {
    for (int Y = 0; Y <= K; ++Y) {
      int sum = S - X - Y;
      if ((sum >= 0) && (sum <= K))
        count++;
    }
  }
  cout << count << endl;

  return 0;
}

// function
template <class T> void printVec(vector<T> vec) {
  // 1要素ずつ、空白・改行なしで出力
  REP(i, vec.size()) { cout << vec.at(i); }
  cout << endl;
}

template <class T> void calcVec(vector<T> &vec, int num, char ch) {
  // vec全体への演算
  if (ch == '+') {
    REP(i, vec.size()) { vec.at(i) += num; }
  } else if (ch == '-') {
    REP(i, vec.size()) { vec.at(i) -= num; }
  } else if (ch == '*') {
    REP(i, vec.size()) { vec.at(i) *= num; }
  } else if (ch == '/') {
    REP(i, vec.size()) { vec.at(i) /= num; }
  } else if (ch == '%') {
    REP(i, vec.size()) { vec.at(i) %= num; }
  }
}

bool checkMultiple(vector<int> &vec, int num) {
  // vecの中身が、numの倍数かどうかのチェック
  int count = 0;
  REP(i, vec.size()) {
    if (vec.at(i) % num != 0)
      count++;
  }
  return (count == 0);
}