Problem p00460 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cassert>
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long LL;
typedef pair<int, int> P;

int N, M, S;
int dp[3000 + 1][2000 + 1];
int dp2[3000 + 1][2000 + 1];
vector<int> ns[8];
vector<int> ms, ss;
vector<int> ret;
int main() {
  while (1) {
    cin >> N >> M >> S;
    if (N == 0 && M == 0 && S == 0)
      break;
    ns[N].push_back((int)ms.size());
    ms.push_back(M);
    ss.push_back(S);
    ret.push_back(0);
  }
  int n = 1;
  for (int i = 0; i <= 2000; i++) {
    dp2[0][i] = 1;
  }
  for (int a = 1; a <= 49; a++) {
    for (int j = 3000; j >= 0; j--) {
      int v = min(2000, j);
      for (int k = 1; k <= v; k++) {
        if (k - 1 >= j - k) {
          dp[j][k] = dp2[j - k][j - k];
        } else {
          dp[j][k] = dp2[j - k][k - 1];
        }
      }
      dp2[j][0] = dp[j][0];
      for (int k = 1; k <= v; k++) {
        dp2[j][k] = dp2[j][k - 1] + dp[j][k];
        if (dp2[j][k] >= 100 * 1000) {
          dp2[j][k] -= 100 * 1000;
        }
      }
    }
    if (a == n * n) {
      for (int i = 0; i < ns[n].size(); i++) {
        int j = ns[n][i];
        if (ms[j] >= ss[j]) {
          ret[j] = dp2[ss[j]][ss[j]];
        } else {
          ret[j] = dp2[ss[j]][ms[j]];
        }
      }
      n++;
    }
  }
  for (int i = 0; i < ret.size(); i++) {
    cout << ret[i] << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cassert>
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long LL;
typedef pair<int, int> P;

int N, M, S;
int dp[3000 + 1][2000 + 1][2];
vector<int> ns[8];
vector<int> ms, ss;
vector<int> ret;
int main() {
  while (1) {
    cin >> N >> M >> S;
    if (N == 0 && M == 0 && S == 0)
      break;
    ns[N].push_back((int)ms.size());
    ms.push_back(M);
    ss.push_back(S);
    ret.push_back(0);
  }
  int n = 1;
  for (int i = 0; i <= 2000; i++) {
    dp[0][i][1] = 1;
  }
  for (int a = 1; a <= 49; a++) {
    for (int j = 3000; j >= 0; j--) {
      int v = min(2000, j);
      for (int k = 1; k <= v; k++) {
        dp[j][k][0] = dp[j - k][k - 1][1];
      }
      dp[j][0][1] = dp[j][0][0];
      for (int k = 1; k <= 2000; k++) {
        dp[j][k][1] = dp[j][k - 1][1] + dp[j][k][0];
        if (dp[j][k][1] >= 100 * 1000) {
          dp[j][k][1] -= 100 * 1000;
        }
      }
    }
    if (a == n * n) {
      for (int i = 0; i < ns[n].size(); i++) {
        int j = ns[n][i];
        ret[j] = dp[ss[j]][ms[j]][1];
      }
      n++;
    }
  }
  for (int i = 0; i < ret.size(); i++) {
    cout << ret[i] << endl;
  }
}