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

#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeinfo>
#include <utility>
#include <vector>

using namespace std;

#define dump(n) cout << "# " << #n << "=" << (n) << endl
#define debug(n)                                                               \\
  cout << __FILE__ << "," << __LINE__ << ": #" << #n << "=" << (n) << endl
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, n) repi(i, 0, n)
#define iter(c) __typeof((c).begin())
#define foreach(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define allof(c) (c).begin(), (c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;

// int solve(int n,int m,int s)
//{
//	static int dp[2][2001][3001];
//	memset(dp,0,sizeof(dp));
//
//	m=min(m,s);
//	repi(i,1,m+1)
//		repi(j,1,i+1)
//			dp[1][i][j]=1;
//
//	repi(i,2,n*n+1){
//		memset(dp[i&1],0,2001*3001*sizeof(int));
//		//repi(j,1,m+1){
//		//	repi(k,1,s+1){
//		repi(j,i,m+1){
//			repi(k,i*(i+1)/2,s+1){
//				dp[i&1][j][k]=dp[i&1][j-1][k];
//				if(j<=k)
//					dp[i&1][j][k]+=dp[(i-1)&1][j-1][k-j];
//				dp[i&1][j][k]%=100000;
//			}
//		}
//	}
//
//	return dp[(n*n)&1][m][s];
// }

int solve(int n, int m, int s) {
  static int dp[2][50][3001];
  memset(dp, 0, sizeof(dp));

  m = min(m, s);

  repi(i, 1, m + 1) {
    // memset(dp[i&1],0,50*3001*sizeof(int));
    repi(j, 1, i + 1) dp[i & 1][1][j] = 1;
    repi(j, 2, n * n + 1) {
      // repi(k,1,s+1){
      repi(k, j * (j + 1) / 2, s + 1) {
        dp[i & 1][j][k] = dp[(i - 1) & 1][j][k];
        if (i <= k)
          dp[i & 1][j][k] += dp[(i - 1) & 1][j - 1][k - i];
        dp[i & 1][j][k] %= 100000;
      }
    }
  }

  return dp[m & 1][n * n][s];
}

int main() {
  for (int n, m, s; cin >> n >> m >> s, n | m | s;) {
    // clock_t begin=clock();
    cout << solve(n, m, s) << endl;
    // printf("time: %ldms\\n",clock()-begin);
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeinfo>
#include <utility>
#include <vector>

using namespace std;

#define dump(n) cout << "# " << #n << "=" << (n) << endl
#define debug(n)                                                               \\
  cout << __FILE__ << "," << __LINE__ << ": #" << #n << "=" << (n) << endl
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, n) repi(i, 0, n)
#define iter(c) __typeof((c).begin())
#define foreach(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define allof(c) (c).begin(), (c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;

int dp[2][2001][3001];

int main() {
  for (int n, m, s; cin >> n >> m >> s, n | m | s;) {
    // clock_t begin=clock();
    memset(dp, 0, sizeof(dp));

    m = min(m, s);
    repi(i, 1, m + 1) repi(j, 1, i + 1) dp[1][i][j] = 1;

    repi(i, 2, n * n + 1) {
      memset(dp[i & 1], 0, 2001 * 3001 * sizeof(int));
      // repi(j,1,m+1){
      //	repi(k,1,s+1){
      repi(j, i, m + 1) {
        repi(k, i * (i + 1) / 2, s + 1) {
          dp[i & 1][j][k] = dp[i & 1][j - 1][k];
          if (j <= k)
            dp[i & 1][j][k] += dp[(i - 1) & 1][j - 1][k - j];
          dp[i & 1][j][k] %= 100000;
        }
      }
    }
    cout << dp[(n * n) & 1][m][s] << endl;

    // printf("time: %ldms\\n",clock()-begin);
  }

  return 0;
}