alexjercan/bugnet huggingface dataset:
Problem p00460 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>

using namespace std;

#define rep(i, n) for (int i = 0; i < n; i++)
#define reps(i, n) for (int i = 1; i <= n; i++)

int dp[50][2][3001];

int main() {

  while (1) {
    int n, m, s;
    scanf("%d%d%d", &n, &m, &s);
    if (n == 0)
      break;
    int t1 = 0, t2 = 1;
    n *= n;
    rep(i, 50) rep(j, 2) rep(k, s + 1) dp[i][j][k] = 0;
    dp[0][0][0] = 1;
    reps(j, m) {

      dp[0][t2][0] = 1;

      reps(i, n) {
        int nn = i;
        int st = (nn * (nn + 1)) / 2;
        for (int k = st - 1; k < s + 1; k++) {
          dp[i][t2][k] = 0;
          if (k - j >= 0) {
            dp[i][t2][k] += dp[i - 1][t1][k - j];
          }
          dp[i][t2][k] += dp[i][t1][k];
          if (dp[i][t2][k] < 0)
            puts("AAAAAAA");
          dp[i][t2][k] %= 100000;
        }
        /*
        if(i<9&&j<9){
                printf("%d %d\\n",i,j);
                for(int k=0;k<50;k++){
                        printf("%d ",dp[i][t2][k]);
                }puts("");
        }*/
      }
      swap(t1, t2);
    }

    printf("%d\\n", dp[n][t1][s]);
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>

using namespace std;

#define rep(i, n) for (int i = 0; i < n; i++)
#define reps(i, n) for (int i = 1; i <= n; i++)

int dp[50][2][3001];

int main() {

  while (1) {
    int n, m, s;
    scanf("%d%d%d", &n, &m, &s);
    if (n == 0)
      break;
    int t1 = 0, t2 = 1;
    n *= n;
    rep(i, 50) rep(j, 2) rep(k, s + 1) dp[i][j][k] = 0;
    dp[0][0][0] = 1;
    reps(j, m) {

      rep(i, n + 1) {
        rep(k, s + 1) { dp[i][t2][k] = 0; }
      }
      dp[0][t2][0] = 1;

      reps(i, n) {
        rep(k, s + 1) {
          if (k - j >= 0) {
            dp[i][t2][k] += dp[i - 1][t1][k - j];
          }
          dp[i][t2][k] += dp[i][t1][k];
          if (dp[i][t2][k] < 0)
            puts("AAAAAAA");
          dp[i][t2][k] %= 100000;
        }
      }
      swap(t1, t2);
    }

    /*
    reps(i,10){
            reps(j,10){
                    printf("%d %d\\n",i,j);
                    rep(k,50){
                            printf("%d ",dp[i][j][k]);
                    }puts("");
            }
    }*/
    printf("%d\\n", dp[n][t1][s]);
  }
}
Problem p00460 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>

using namespace std;
int DP[2][2002][3001];

int main() {

  int n, m, s;
  while (true) {
    cin >> n >> m >> s;
    if (n == 0) {
      break;
    }
    n *= n;

    for (int i = 0; i <= m; i++) {
      for (int j = 0; j <= s; j++) {
        DP[0][i][j] = 0;
        DP[1][i][j] = 0;
      }
      DP[1][i][i] = 1;
    }
    DP[1][0][0] = 0;

    for (int i = 2; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
        for (int k = j; k <= s; k++) {
          DP[i % 2][j][k] =
              DP[i % 2][j - 1][k - 1] + DP[(i + 1) % 2][j - 1][k - j];
          DP[i % 2][j][k] %= 100000;
        }
      }
    }

    int ans = 0;
    for (int i = 0; i <= m; i++) {
      ans += DP[n % 2][i][s];
      ans %= 100000;
    }
    cout << ans << endl;
  }
  return 0;
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>

using namespace std;
int DP[50][2002][3001];

int main() {

  for (int i = 0; i <= 2001; i++) {
    for (int j = 0; j <= 3000; j++) {
      DP[0][i][j] = 0;
    }
    DP[1][i][i] = 1;
  }
  DP[1][0][0] = 0;
  for (int i = 2; i < 50; i++) {
    for (int j = 1; j <= 2000; j++) {
      for (int k = j; k <= 3000; k++) {
        DP[i][j][k] = DP[i][j - 1][k - 1] + DP[i - 1][j - 1][k - j];
        DP[i][j][k] %= 100000;
      }
    }
  }

  int n, m, s;
  while (true) {
    cin >> n >> m >> s;
    if (n == 0) {
      break;
    }
    n *= n;
    int ans = 0;
    for (int i = 0; i <= m; i++) {
      ans += DP[n][i][s];
      ans %= 100000;
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p00460 (C++) — buggy submission, verdict: Memory Limit Exceeded


#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 100000
#define rep(i, n) for (i = 0; i < (n); i++)
#define loop(i, a, n) for (i = a; i < (n); i++)
#define all(in) in.begin(), in.end()
#define shosu(x) fixed << setprecision(x)

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;

int dp[2][55][3005];

int main(void) {
  int i, j, k;
  int n, m, s;
  while (1) {
    cin >> n >> m >> s;
    if (n == 0)
      break;
    rep(i, 2) rep(j, 55) rep(k, 3005) dp[i][j][k] = 0;
    dp[0][0][0] = 1;

    bool c = false;
    rep(i, m) {
      int cnt = 0;
      rep(j, n * n + 1) rep(k, s + 1) if (dp[i % 2][j][k] > 0) {
        //	cout<<i<<" "<<j<<" "<<k<<" "<<dp[i%2][j][k]<<endl;
        (dp[(i + 1) % 2][j][k] += dp[i % 2][j][k]) %= MOD;
        if (k + i + 1 <= s)
          (dp[(i + 1) % 2][j + 1][k + i + 1] += dp[i % 2][j][k]) %= MOD, cnt++;
        dp[i % 2][j][k] = 0;
      }
      if (c && cnt == 0)
        break;
      if (cnt == 0)
        c = true;
    }
    cout << dp[m % 2][n * n][s] << endl;
  }
}


Error: MLE

Fixed submission:


#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 100000
#define rep(i, n) for (i = 0; i < (n); i++)
#define loop(i, a, n) for (i = a; i < (n); i++)
#define all(in) in.begin(), in.end()
#define shosu(x) fixed << setprecision(x)

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;

int dp[2005][55][3005];

int main(void) {
  int i, j, k;
  int n, m, s;
  while (1) {
    cin >> n >> m >> s;
    if (n == 0)
      break;
    rep(i, 2005) rep(j, 55) rep(k, 3005) dp[i][j][k] = 0;
    dp[0][0][0] = 1;

    rep(i, m + 1) rep(j, n * n + 1) rep(k, s + 1) if (dp[i][j][k] > 0) {
      (dp[i + 1][j][k] += dp[i][j][k]) %= MOD;
      if (k + i + 1 <= s)
        (dp[i + 1][j + 1][k + i + 1] += dp[i][j][k]) %= MOD;
    }

    cout << dp[m][n * n][s] << endl;
  }
}
Problem p00460 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <cstring>
#include <iostream>
using namespace std;

int n, m, s;
int dp[50][3001];
int main() {
  while (cin >> n >> m >> s && n) {
    n *= n;
    m = min(m, s);
    memset(dp, 0, sizeof(dp));
    dp[0][0] = 1;
    for (int j = 1; j <= m; j++) {
      for (int k = s - j; k >= 0; k--) {
        for (int i = 1; i <= n; i++) {
          (dp[i][k + j] += dp[i - 1][k]) %= 100000;
        }
      }
    }
    cout << dp[n][s] << endl;
  }
}

Error: MLE

Fixed submission:

#include <cstring>
#include <iostream>
using namespace std;

int n, m, s;
int dp[2][2001][3001];
int pv[2001][3001];
int main() {
  while (cin >> n >> m >> s && n) {
    n *= n;
    m = min(m, s);
    memset(dp[0], 0, sizeof(dp[0]));
    for (int i = 1; i <= m; i++)
      dp[0][i][i] = 1;
    for (int j = 0; j <= m; j++) {
      for (int k = 0; k <= s; k++) {
        pv[j][k] = (j ? pv[j - 1][k] : 0) + dp[0][j][k];
      }
    }
    for (int i = 1; i < n; i++) {
      memset(dp[i & 1], 0, sizeof(dp[i & 1]));
      for (int j = 1; j <= m; j++) {
        for (int k = j; k <= s; k++) {
          (dp[i & 1][j][k] += pv[j - 1][k - j]) %= 100000;
        }
      }
      for (int j = 0; j <= m; j++) {
        for (int k = 0; k <= s; k++) {
          pv[j][k] = (j ? pv[j - 1][k] : 0) + dp[i & 1][j][k];
        }
      }
    }
    int ans = 0;
    for (int i = 0; i <= m; i++) {
      (ans += dp[n & 1 ^ 1][i][s]) %= 100000;
    }
    cout << ans << endl;
  }
}
Problem p00460 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <bits/stdc++.h>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) for (int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x) cerr << #x << " = " << (x) << endl;
using namespace std;

const int M = 100000;

int main() {
  int n, m, s;
  while (cin >> n >> m >> s, n) {
    vector<vector<int>> cur(n * n + 1, vector<int>(s + 1, 0));
    cur[0][0] = 1;
    range(i, 1, m + 1) {
      for (int j = n * n; j > 0; j--) {
        range(k, i, s + 1) { (cur[j][k] += cur[j - 1][k - i]) %= M; }
      }
    }

    cout << cur[n * n][s] << endl;
  }
}


Error: MLE

Fixed submission:

#include <bits/stdc++.h>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) for (int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x) cerr << #x << " = " << (x) << endl;
using namespace std;

const int M = 100000;
int dp
    [2005][3005]
    [50]; // テヲツ慊?・ツセツ古」ツ?ォテ、ツスツソテ」ツ?」テ」ツ?淌ヲツ閉ーテ・ツュツ療」ツ??、ツサツ甘」ツ?セテ」ツ?ァテ」ツ?ォテ、ツスツソテ」ツ?」テ」ツ?淌ヲツ閉ーテ・ツュツ療」ツ?ョテ・ツ青暗ィツィツ暗」ツ??、ツサツ甘」ツ?セテ」ツ?ァテ」ツ?ォテ、ツスツソテ」ツ?」テ」ツ?淌ヲツ閉ーテ・ツュツ療」ツ?ョテ・ツ?凝ヲツ閉ー

int main() {
  int n, m, s;
  while (cin >> n >> m >> s, n) {
    memset(dp, 0, sizeof(dp));
    dp[0][0][0] = 1;
    rep(i, m + 1) {
      range(j, i, s + 1) {
        range(l, 1, n * n + 1) {
          int sum = 0;
          rep(k, i) {
            sum += dp[k][j - i][l - 1];
            sum %= M;
          }
          // cout << i << ' ' << j << endl;
          // show(dp[i][j])
          dp[i][j][l] = max(dp[i][j][l], sum);
        }
      }
    }

    int sum = 0;
    rep(i, m + 1) {
      sum += dp[i][s][n * n];
      sum %= M;
    }
    cout << sum << endl;
  }
}
Problem p00460 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define REP(i, s, e) for (int i = int(s); i <= int(e); i++)
#define rep(i, n) for (int i = 0; i < int(n); i++)

int B[50][3001];

int main() {

  int N, M, S;
  while (1) {

    cin >> N >> M >> S;
    if (N == 0 && M == 0 && S == 0)
      break;

    int mod = 100000;

    B[0][0] = 1;

    for (int k = 1; k <= M; k++) {
      for (int n = N * N; n >= 1; n--) {
        for (int s = S; s >= 1; s--) {

          if (s - k >= 0 && n - 1 >= 0)
            B[n][s] = B[n - 1][s - k] % mod + B[n][s] % mod;
          else
            B[n][s] = B[n][s] % mod;
        }
      }
    }

    cout << B[N * N][S] % mod << endl;

    REP(n, 0, N * N) REP(s, 0, S) B[n][s] = 0;
  }

  return 0;
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define REP(i, s, e) for (int i = int(s); i <= int(e); i++)
#define rep(i, n) for (int i = 0; i < int(n); i++)

int B[2001][50][3001];

int main() {

  int N, M, S;
  while (1) {

    cin >> N >> M >> S;
    if (N == 0 && M == 0 && S == 0)
      break;

    REP(i, 0, N * N) {
      REP(j, 0, S) {
        if (i == 0 && j == 0)
          B[0][i][j] = 1;
        else
          B[0][i][j] = 0;
      }
    }

    int mod = 100000;

    REP(n, 0, N * N) {
      REP(k, 0, M - 1) {
        REP(s, 0, S) {

          if (s - (k + 1) >= 0 && n - 1 >= 0)
            B[k + 1][n][s] = B[k][n - 1][s - (k + 1)] % mod + B[k][n][s] % mod;
          else
            B[k + 1][n][s] = B[k][n][s] % mod;
        }
      }
    }

    cout << B[M][N * N][S] % mod << endl;

    REP(k, 0, M) REP(n, 0, N * N) REP(s, 0, S) B[k][n][s] = 0;
  }

  return 0;
}
Problem p00460 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int dp[2][2001][3001];
const int mod = 100000;
int main() {
  int n, m, s;
  while (cin >> n >> m >> s) {
    if (n == 0)
      break;
    n *= n;

    for (int j = 0; j <= m; j++)
      for (int k = 0; k <= s; k++)
        dp[0][j][k] = 0;

    dp[0][0][0] = 1;
    for (int i = 0; i <= n; i++) {
      int now = i & 1;
      int next = now ^ 1;

      for (int j = 0; j <= m; j++)
        for (int k = 0; k <= s; k++)
          dp[next][j][k] = 0;

      for (int j = 0; j < m; j++) {
        for (int k = 0; k <= s; k++) {
          if (dp[now][j][k] == 0)
            continue;
          (dp[now][j + 1][k] += dp[now][j][k]) %= mod;
          if (k + j + 1 <= s)
            (dp[next][j + 1][k + j + 1] += dp[now][j][k]) %= mod;
          // cout << dp[now][j+1][k] << " " ;
        }
        // cout << endl;
      }
      // cout << endl;
    }
    cout << dp[n & 1][m][s] << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int dp[2][2001][3001];
const int mod = 100000;
int main() {
  int n, m, s;
  while (cin >> n >> m >> s) {
    if (n == 0)
      break;
    n *= n;
    dp[0][0][0] = 1;
    for (int i = 0; i < n; i++) {
      int now = i & 1;
      int next = now ^ 1;

      for (int j = 0; j <= m; j++)
        for (int k = 0; k <= s; k++)
          dp[next][j][k] = 0;

      for (int j = 0; j <= m; j++) {
        for (int k = 0; k <= s; k++) {
          if (dp[now][j][k] == 0)
            continue;
          (dp[now][j + 1][k] += dp[now][j][k]) %= mod;
          if (k + j + 1 <= s)
            (dp[next][j + 1][k + j + 1] += dp[now][j][k]) %= mod;
          cout << dp[now][j + 1][k] << " ";
        }
        cout << endl;
      }
      cout << endl;
    }
    for (int i = 0; i < m; i++) {
      (dp[n & 1][i + 1][s] += dp[n & 1][i][s]) %= mod;
    }
    cout << dp[n & 1][m][s] << endl;
  }
  return 0;
}
Problem p00460 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl;
int mod = 100000;
int dp[2][50][3001];
void add(int &x, int y) {
  x += y;
  if (x >= mod)
    x -= mod;
}
int main() {
  while (true) {
    int n, m, s;
    scanf("%d%d%d", &n, &m, &s);
    if (n == 0)
      break;
    n = n * n;
    rep(j, n + 1) rep(k, s + 1) dp[0][j][k] = 0;
    dp[0][0][0] = 1;
    rep(i, m) {
      rep(j, n + 1) rep(k, s + 1) dp[1 - i % 2][j][k] = 0;
      rep(j, n + 1) {
        rep(k, s + 1) {
          if ((i * 2 + 1 + n - j) * (n - j) / 2 > s)
            break;
          add(dp[1 - i % 2][j][k], dp[i % 2][j][k]);
          if (j + 1 <= n && k + i + 1 <= s)
            add(dp[1 - i % 2][j + 1][k + i + 1], dp[i % 2][j][k]);
        }
      }
    }
    cout << dp[m % 2][n][s] << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl;
int mod = 100000;
int dp[2][50][3001];
void add(int &x, int y) {
  x += y;
  if (x >= mod)
    x -= mod;
}
int main() {
  while (true) {
    int n, m, s;
    cin >> n >> m >> s;
    if (n == 0)
      break;
    n = n * n;
    rep(j, n + 1) rep(k, s + 1) dp[0][j][k] = 0;
    dp[0][0][0] = 1;
    rep(i, m) {
      rep(j, n + 1) rep(k, s + 1) dp[1 - i % 2][j][k] = 0;
      rep(j, n + 1) {
        rep(k, s + 1) {
          add(dp[1 - i % 2][j][k], dp[i % 2][j][k]);
          if (j + 1 <= n && k + i + 1 <= s)
            add(dp[1 - i % 2][j + 1][k + i + 1], dp[i % 2][j][k]);
        }
      }
    }
    cout << dp[m % 2][n][s] << endl;
  }
}
Problem p00460 (C++) — buggy submission, verdict: Time Limit Exceeded

/* 剰余取り忘れてしもたwガハハw　*/
#include <stdio.h>
#include <string.h>

int dp[50][3001];

int main() {
  while (1) {
    int i;
    int n, m, s;
    int square;

    scanf("%d %d %d", &n, &m, &s);
    if (n == 0 && m == 0 && s == 0) {
      return 0;
    }

    memset(dp, 0, sizeof(dp));

    square = n * n;
    dp[0][0] = 1;

    for (i = 1; i < m + 1; i++) {
      int j;

      for (j = s; j >= i; j--) {
        int k;

        for (k = 0; k < square; k++) {
          dp[k + 1][j] += dp[k][j - i];
          dp[k + 1][j] %= 100000;
        }
      }
    }

    printf("%d\\n", dp[square][s]);
  }
}

Error: TLE

Fixed submission:

/* 絶対通らないはあ辛い */
#include <stdio.h>

int dp[50][2][3001];

int main() {
  while (1) {
    int i;
    int n, m, s;
    int square;
    int first_val;
    int sum = 0;

    scanf("%d %d %d", &n, &m, &s);
    if (n == 0 && m == 0 && s == 0) {
      return 0;
    }

    square = n * n;
    first_val = square * (square + 1) / 2;

    for (i = 0; i < square + 1; i++) {
      int j;

      for (j = 0; j < 2; j++) {
        int k;

        for (k = 0; k < s + 1; k++) {
          dp[i][j][k] = 0;
        }
      }
    }

    dp[square][0][first_val] = 1;

    for (i = square; i < m + 1; i++) {
      int j;

      for (j = first_val; j < s + 1; j++) {
        int k;

        for (k = 1; k < square + 1; k++) {
          int l;

          for (l = 1; l <= k; l++) {
            if (i + 1 > m || j + l > s)
              break;

            dp[l][1][j + l] += dp[k][0][j];
            dp[l][1][j + l] %= 100000;
          }
        }
      }

      for (j = 1; j < square + 1; j++) {
        sum += dp[j][0][s];
        sum %= 100000;
      }

      for (j = first_val; j < s + 1; j++) {
        int k;

        for (k = 1; k < square + 1; k++) {
          dp[k][0][j] = dp[k][1][j];
          dp[k][1][j] = 0;
        }
      }
    }

    /*for (i=1; i<square+1; i++) {
        sum += dp[i][0][s];
        sum %= 100000;
    }*/

    printf("%d\\n", sum);
  }
}
Problem p00460 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstring>
#include <iostream>

using namespace std;

int dp[2][3001][50];
const int mod = 100000;
int n, m, s;

int main() {
  while (cin >> n >> m >> s && (n | m | s)) {
    memset(dp, 0, sizeof(dp));
    for (int i = 0; i < 2; i++)
      dp[i][0][n * n] = 1;
    for (int i = m; i >= 0; i--) {
      for (int j = 0; j <= s; j++) {
        for (int k = n * n; k >= 0; k--) {
          int cur = (i + 1) % 2;
          int nxt = i % 2;
          int res = 0;
          if (k == n * n) {
            if (j == 0)
              res = 1;
            else
              res = 0;
          } else {
            res += dp[cur][j][k];
            if (j - i >= 0)
              res += dp[cur][j - i][k + 1];
          }
          dp[nxt][j][k] = res % mod;
        }
      }
    }
    cout << dp[1][s][0] % mod << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstring>
#include <iostream>

using namespace std;

int dp[2][3001][50];

const int mod = 100000;
int n, m, s;

int main() {

  while (cin >> n >> m >> s && (n | m | s)) {
    memset(dp, 0, sizeof(dp));
    for (int i = 0; i < 2; i++)
      dp[i][0][n * n] = 1;
    for (int i = m; i >= 0; i--) {
      for (int j = 0; j <= s; j++) {
        for (int k = n * n; k >= 0; k--) {
          int cur = (i + 1) % 2;
          int nxt = i % 2;
          int pos = i;
          int lefts = j;
          int cnts = k;
          int res = 0;
          if (k == n * n) {
            if (j == 0)
              dp[nxt][lefts][cnts] = 1;
            else
              dp[nxt][lefts][cnts] = 0;
          } else {
            res += dp[cur][lefts][cnts];
            if (lefts - pos >= 0)
              res += dp[cur][lefts - pos][cnts + 1];
            dp[nxt][lefts][cnts] = res % mod;
          }
        }
      }
    }
    cout << dp[1][s][0] % mod << endl;
  }
  return 0;
}
Problem p00460 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstring>
#include <iostream>

using namespace std;

int dp[2][3001][50];
const int mod = 100000;
int n, m, s;

int main() {
  while (cin >> n >> m >> s && (n | m | s)) {
    memset(dp, 0, sizeof(dp));
    for (int i = 0; i < 2; i++)
      dp[i][0][n * n] = 1;
    for (int i = m; i >= 0; i--) {
      for (int j = 0; j <= s; j++) {
        for (int k = n * n; k >= 0; k--) {
          int cur = (i + 1) % 2;
          int nxt = i % 2;
          int res = 0;
          if (k == n * n) {
            if (j == 0)
              res = 1;
            else
              res = 0;
          } else {
            res += dp[cur][j][k];
            if (j - i >= 0)
              res += dp[cur][j - i][k + 1];
          }
          dp[nxt][j][k] = res % mod;
        }
      }
    }
    cout << dp[1][s][0] % mod << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstring>
#include <iostream>

using namespace std;

int dp[2][3001][50];
const int mod = 100000;
int n, m, s;

int main() {
  while (cin >> n >> m >> s && (n | m | s)) {
    memset(dp, 0, sizeof(dp));
    for (int i = 0; i < 2; i++)
      dp[i][0][n * n] = 1;
    for (int i = m; i >= 0; i--) {
      for (int j = 0; j <= s; j++) {
        for (int k = n * n; k >= 0; k--) {
          int cur = (i + 1) % 2;
          int nxt = i % 2;
          dp[nxt][j][k] = 0;
          if (k == n * n) {
            if (j == 0)
              dp[nxt][j][k] = 1;
            else
              dp[nxt][j][k] = 0;
          } else {
            dp[nxt][j][k] += dp[cur][j][k];
            if (j - i >= 0)
              dp[nxt][j][k] += dp[cur][j - i][k + 1];
          }
          dp[nxt][j][k] %= mod;
        }
      }
    }
    cout << dp[1][s][0] % mod << endl;
  }
  return 0;
}
Problem p00460 (C++) — buggy submission, verdict: Runtime Error

#include <cstring>
#include <iostream>
using namespace std;

const int mod = 100000;
int main() {
  int n, m, s;
  int dp[50][3001];
  while (cin >> n >> m >> s, n) {
    memset(dp, 0, sizeof(dp));
    dp[0][0] = 1;
    for (int i = 1; i <= m; ++i) {
      for (int j = n * n - 1; j >= 0; --j) {
        for (int k = 0; k <= s - i; ++k) {
          dp[j + 1][k + i] += dp[j][k];
          dp[j + 1][k + i] %= mod;
        }
      }
    }
    cout << dp[n * n][s] << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <cstring>
#include <iostream>
using namespace std;

const int mod = 100000;
int main() {
  int n, m, s;
  int dp[50][2001];
  while (cin >> n >> m >> s, n) {
    memset(dp, 0, sizeof(dp));
    dp[0][0] = 1;
    for (int i = 1; i <= m; ++i) {
      for (int j = n * n - 1; j >= 0; --j) {
        for (int k = 0; k <= s - i; ++k) {
          dp[j + 1][k + i] += dp[j][k];
          dp[j + 1][k + i] %= mod;
        }
      }
    }
    cout << dp[n * n][s] << endl;
  }
  return 0;
}