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

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, s;
  while (scanf("%d %d %d", &n, &m, &s), n != 0 && m != 0 && s != 0) {
    int sum[50][3001] = {};
    sum[0][0] = 1;
    for (int i = 1; i <= m; i++) {
      for (int j = min(i, n * n); j > 0; j--) {
        for (int k = i; k <= s; k++) {
          sum[j][k] = (sum[j][k] + sum[j - 1][k - i]) % 100000;
        }
      }
    }
    printf("%d\\n", sum[n * n][s]);
  }
  return (0);
}

Error: MLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int n, m, s;
int memo[2001][3001][50];
int dfs(int num, int sum, int cou) {
  if (cou == n * n + 1) {
    if (sum == s)
      return 1;
    else
      return 0;
  }
  if (memo[num][sum][cou] != -1)
    return memo[num][sum][cou];
  int ret = 0;
  for (int i = num; i <= m; i++) {
    ret = (ret + dfs(i + 1, sum + i, cou + 1)) % 100000;
  }
  return memo[num][sum][cou] = ret;
}
int main() {
  while (scanf("%d %d %d", &n, &m, &s) && n != 0 && m != 0 && s != 0) {
    fill_n(**memo, 2001 * 3001 * 50, -1);
    printf("%d\\n", dfs(1, 0, 1));
  }
  return (0);
}
Problem p00460 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <string.h>
using namespace std;

int n, m, s, ans;
int dp[2][2001][3001];

int main() {
  while (scanf("%d%d%d", &n, &m, &s) && n && m && s) {
    for (int i = 1; i <= m; i++)
      dp[0][i][i] = 1;

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

    for (int i = 1; i <= m; i++) {
      ans += dp[0][i][s];
      ans %= 100000;
    }

    printf("%d\\n", ans);
    memset(dp, 0, sizeof dp);
    ans = 0;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <string.h>
using namespace std;

int n, m, s, ans;
int dp[2][2001][3001];

int main() {
  while (scanf("%d%d%d", &n, &m, &s) && n && m && s) {
    for (int i = 1; i <= m; i++)
      dp[0][i][i] = 1;

    for (int i = 2; i <= n * n; i++) {
      for (int j = 1; j <= m; j++) {
        for (int k = 1; k < j; k++) {
          for (int l = 1; l <= s; l++) {
            if (j + l > s) {
              break;
            } else {
              dp[1][j][j + l] += dp[0][k][l];
              dp[1][j][j + l] %= 100000;
            }
          }
        }
      }
      for (int j = 1; j <= m; j++) {
        for (int k = 1; k <= s; k++) {
          dp[0][j][k] = dp[1][j][k];
          dp[1][j][k] = 0;
        }
      }
    }

    for (int i = 1; i <= m; i++) {
      ans += dp[0][i][s];
      ans %= 100000;
    }

    printf("%d\\n", ans);
    memset(dp, 0, sizeof dp);
    ans = 0;
  }

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

#include <cstdio>
#include <iostream>
using namespace std;
#define LATTE 100000

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

int main() {
  int N, M, S;
  while (cin >> N >> M >> S, N || M || S) {
    for (int i = 1; i <= M; i++)
      for (int j = 1; j <= S; j++)
        dp[0][i][j] = dp[1][i][j] = 0;
    for (int i = 1; i <= M; i++) {
      dp[1][i][i] = 1;
    }
    for (int i = 1; i < N * N; i++) {
      for (int j = 1; j <= M; j++) {
        for (int k = 1; k <= S; k++) {
          // printf("%d,%d,%d\\n",i,j,k);
          if (k + j + 1 <= S && j + 1 <= M) {
            dp[(i + 1) & 1][j + 1][k + j + 1] +=
                dp[i & 1][j][k] + dp[(i + 1) & 1][j][k + j];
            dp[(i + 1) & 1][j + 1][k + j + 1] %= LATTE;
          }
          dp[i & 1][j][k] = 0;
          /*for(int l=j+1;l<=50;l++){
              dp[i+1][l][k+l] += dp[i][j][k];
              dp[i+1][l][k+l]%=LATTE;
          }*/
        }
      }
    }
    int ans = 0;
    for (int i = 1; i <= M; i++) {
      ans += dp[(N * N) & 1][i][S];
    }
    printf("%d\\n", ans % LATTE);
  }
  return 0;
}

Error: MLE

Fixed submission:

#include <cstdio>
#include <iostream>
using namespace std;
#define LATTE 100000

int dp[50][2001][3001];

int main() {
  for (int i = 1; i <= 2000; i++) {
    dp[1][i][i] = 1;
  }
  for (int i = 1; i < 49; i++) {
    for (int j = 1; j < 2000; j++) {
      for (int k = 1; k < 3000; k++) {
        if (k + j + 1 > 3000)
          break;
        dp[i + 1][j + 1][k + j + 1] += dp[i][j][k] + dp[i + 1][j][k + j];
        dp[i + 1][j + 1][k + j + 1] %= LATTE;
        /*for(int l=j+1;l<=50;l++){
            dp[i+1][l][k+l] += dp[i][j][k];
            dp[i+1][l][k+l]%=LATTE;
        }*/
      }
    }
  }
  int N, M, S;
  while (cin >> N >> M >> S) {
    int ans = 0;
    for (int i = 1; i <= M; i++) {
      ans += dp[N * N][i][S];
    }
    printf("%d\\n", ans % LATTE);
  }
  return 0;
}
Problem p00460 (C++) — buggy submission, verdict: Time Limit Exceeded

// Solution for aoj:0537 Bingo
#include <algorithm>
#include <iostream>
#include <set>
#include <vector>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
using namespace std;
const int surplus = 100000;
int N, ans;
int b[2][2001][3001];
int main() {
  int n, m, s;
  while (cin >> n >> m >> s) {
    if (!n && !m && !s)
      return 0;
    ans = 0;
    N = n * n;
    FOR(i, 1, m + 1)
    b[0][i][i] = 1;
    for (int i = 2; i < N + 1; i++) {
      for (int j = 1; j < m; j++) {
        for (int k = j; k < s; k++) {
          b[1][j + 1][k + 1] = b[1][j][k] + b[0][j][k - j];
          b[1][j + 1][k + 1] %= surplus;
          if (i == N && k + 1 == s) {
            ans += b[1][j + 1][k + 1];
          }
        }
      }
      FOR(j, 1, m) {
        FOR(k, 1, s) {
          b[0][j][k] = b[1][j][k];
          if (i == N)
            b[0][j][k] = 0;
        }
      }
    }
    cout << ans % surplus << endl;
  }
}

Error: TLE

Fixed submission:

// Solution for aoj:0537 Bingo
#include <algorithm>
#include <iostream>
#include <set>
#include <vector>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REVERSE(i, a, b) for (int i = (a); i > (b); i--)
using namespace std;
const int surplus = 100000;
int N, ans;
int b[2][2001][3001];
int main() {
  int n, m, s;
  while (cin >> n >> m >> s) {
    if (!n && !m && !s)
      return 0;
    ans = 0;
    N = n * n;
    FOR(i, 1, m + 1)
    b[0][i][i] = 1;
    FOR(i, 2, N + 1) {
      FOR(j, 1, m) {
        FOR(k, 1, s) {
          b[1][j + 1][k + 1] = b[1][j][k] + b[0][j][k - j];
          b[1][j + 1][k + 1] %= surplus;
          if (i == N && k + 1 == s) {
            ans += b[1][j + 1][k + 1];
          }
        }
      }
      FOR(j, 1, m) {
        FOR(k, 1, s) {
          b[0][j][k] = b[1][j][k];
          b[1][j][k] = 0;
          if (i == N)
            b[0][j][k] = 0;
        }
      }
    }
    cout << ans % surplus << endl;
  }
}
Problem p00460 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define mod 100000
typedef pair<int, int> P;
int n, m, s, ans;
int dp[2][2001][3001];
int main() {
  while (cin >> n >> m >> s && n) {
    memset(dp, 0, sizeof(dp));
    dp[0][0][0] = 1;
    for (int i = 0; i < n * n; ++i) {
      for (int j = 0; j < m; ++j)
        for (int k = j; k < s; ++k)
          dp[1][j + 1][k + 1] = (dp[1][j][k] + dp[0][j][k - j]) % mod;
      for (int j = 0; j <= m; ++j) {
        for (int k = 0; k <= s; ++k) {
          dp[0][j][k] = dp[1][j][k];
          dp[1][j][k] = 0;
        }
      }
    }
    ans = 0;
    for (int i = 0; i <= m; ++i) {
      ans += dp[0][i][s];
      ans %= mod;
    }
    cout << ans << endl;
  }
}

Error: MLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define mod 100000
typedef pair<int, int> P;
int n, m, s, ans;
int dp[2][3010][4010];
int main() {
  while (cin >> n >> m >> s && n) {
    memset(dp, 0, sizeof(dp));
    dp[0][0][0] = 1;
    for (int i = 0; i < n * n; ++i) {
      for (int j = 0; j < m; ++j)
        for (int k = j; k < s; ++k)
          dp[1][j + 1][k + 1] = (dp[1][j][k] + dp[0][j][k - j]) % mod;
      for (int j = 0; j <= m; ++j) {
        for (int k = 0; k <= s; ++k) {
          dp[0][j][k] = dp[1][j][k];
          dp[1][j][k] = 0;
        }
      }
    }
    ans = 0;
    for (int i = 0; i <= m; ++i) {
      ans += dp[0][i][s];
      ans %= mod;
    }
    cout << ans << endl;
  }
}
Problem p00460 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;

int N, M, S;
int dp[50][3001]; // dp[i][j][k] i????????°??§ j??????????????????????????°
const int MOD = 100000;

int main() {
  while (cin >> N >> M >> S, N * M) {
    dp[0][0] = 1;
    for (int m = 1; m <= M; m++) {
      for (int n = N * N; n > 0; n--) {
        for (int s = m; s <= S; s++) {
          dp[n][s] += dp[n - 1][s - m];
          dp[n][s] %= MOD;
        }
      }
    }
    cout << dp[N * N][S] % MOD << endl;
    for (int i = 0; i <= N * N; i++)
      for (int j = 1; j <= S; j++)
        dp[i][j] = 0;
  }
  return 0;
}

// I have a little question about this problem.

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int N, M, S;
int dp[2][3001][2001]; // dp[i][j][k] i????????°??§ j?????????
                       // ?????§???k?????????????????°
const int MOD = 100000;

int main() {
  while (cin >> N >> M >> S, N * M) {
    for (int i = 1; i <= S; i++) {
      dp[0][i][i] = 1;
    }
    for (int i = 0; i < N * N - 1; i++) {
      for (int j = 1; j <= S; j++) {
        for (int k = 1; k <= j; k++) {
          for (int l = k + 1; l <= M; l++) {
            if (j + l <= S) {
              dp[(i + 1) % 2][j + l][l] += dp[i % 2][j][k];
              dp[(i + 1) % 2][j + l][l] %= MOD;
            }
          }
          dp[i % 2][j][k] = 0;
        }
      }
    }
    int ans = 0;
    for (int i = 1; i <= M; i++) {
      ans += dp[(N * N - 1) % 2][S][i];
    }
    cout << ans % MOD << endl;
    for (int i = 0; i <= 1; i++)
      for (int j = 1; j <= S; j++)
        for (int k = 1; k <= M; k++)
          dp[i][j][k] = 0;
  }
  return 0;
}
Problem p00460 (C++) — buggy submission, verdict: Memory Limit Exceeded

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

int main() {
  while (1) {
    int n, m, s;
    static int dp[2][2002][3002];
    for (int i = 0; i < 2; i++)
      for (int j = 0; j < 2002; j++)
        for (int k = 0; k < 3002; k++)
          dp[i][j][k] = 0;
    scanf("%d%d%d", &n, &m, &s);
    if (n == 0 && m == 0 && s == 0)
      break;
    for (int j = 0; j <= m; j++)
      dp[0][j][0] = 1;
    for (int i = 1; i <= n * n; i++) {
      for (int j = 1; j <= m; j++) {
        for (int k = 1; k <= s; k++) {
          if (k - j >= 0) {
            dp[1][j][k] = dp[0][j - 1][k - j];
          }
          dp[1][j][k] += dp[1][j - 1][k];
          dp[1][j][k] %= 100000;
        }
      }
      for (int j = 0; j <= m; j++)
        for (int k = 0; k <= s; k++) {
          dp[0][j][k] = dp[1][j][k];
          dp[1][j][k] = 0;
        }
    }
    printf("%d\\n", dp[0][m][s]);
  }
}

Error: MLE

Fixed submission:

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

int main() {
  while (1) {
    int n, m, s;
    static int dp[27][2002][3002] = {0};
    scanf("%d%d%d", &n, &m, &s);
    if (n == 0 && m == 0 && s == 0)
      break;
    for (int j = 0; j <= m; j++)
      dp[0][j][0] = 1;
    for (int i = 1; i <= n * n; i++) {
      for (int j = 1; j <= m; j++) {
        for (int k = 1; k <= s; k++) {
          if (k - j >= 0) {
            dp[i][j][k] = dp[i - 1][j - 1][k - j];
          }
          dp[i][j][k] += dp[i][j - 1][k];
          dp[i][j][k] %= 100000;
        }
      }
    }
    printf("%d\\n", dp[n * n][m][s]);
  }
}
Problem p00460 (C++) — buggy submission, verdict: Runtime Error


// y09-6 ビンゴ(2回目)
#include <algorithm>
#include <cassert>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
#define LL long long
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define LL_MIN -9223372036854775808
#define LL_MAX 9223372036854775807
#define segment_size 65536
#define ROOP() while (true)

int main() {
  ROOP() {
    int N, M, S;
    cin >> N >> M >> S;
    if (N == 0)
      return 0;
    M = min(M, S);

    int dp[50][3001];
    for (int i = 0; i < 50; i++) {
      for (int j = 0; j < 3001; j++) {
        dp[i][j] = 0;
      }
    }
    dp[0][0] = 1;

    for (int i = 1; i <= N * N; i++) {
      for (int j = 1; j <= S; j++) {
        if (j >= i)
          dp[i][j] = dp[i - 1][j - i] + dp[i][j - i];
        if (j > M)
          dp[i][j] -= dp[i - 1][j - M - 1];
        dp[i][j] %= 100000;
        if (dp[i][j] < 0)
          dp[i][j] += 100000;
      }
    }
    cout << dp[N * N][S] << endl;
  }
  return 0;
}


Error: -11

Fixed submission:


// y09-6 ビンゴ(2回目)
#include <algorithm>
#include <cassert>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
#define LL long long
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define LL_MIN -9223372036854775808
#define LL_MAX 9223372036854775807
#define segment_size 65536
#define ROOP() while (true)

int main() {
  ROOP() {
    int N, M, S;
    cin >> N >> M >> S;
    if (N == 0)
      return 0;

    int dp[50][3001];
    for (int i = 0; i < 50; i++) {
      for (int j = 0; j < 3001; j++) {
        dp[i][j] = 0;
      }
    }
    dp[0][0] = 1;

    for (int i = 1; i <= M; i++) {
      for (int j = 1; j <= N * N; j--) {
        for (int k = i; k <= S; k++) {
          dp[j][k] += dp[j - 1][k - i];
          dp[j][k] %= 100000;
        }
      }
    }
    cout << dp[N * N][S] << endl;
  }
  return 0;
}
Problem p00460 (C++) — buggy submission, verdict: Runtime Error


// y09-6 ビンゴ(2回目)
#include <algorithm>
#include <cassert>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
#define LL long long
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define LL_MIN -9223372036854775808
#define LL_MAX 9223372036854775807
#define segment_size 65536
#define ROOP() while (true)

int main() {
  ROOP() {
    int N, M, S;
    cin >> N >> M >> S;
    if (N == 0)
      return 0;

    int dp[50][3001];
    for (int i = 0; i < 50; i++) {
      for (int j = 0; j < 3001; j++) {
        dp[i][j] = 0;
      }
    }
    dp[0][0] = 1;

    for (int i = 1; i <= M; i++) {
      for (int j = N * N; j >= 1; j--) {
        for (int k = i; k <= S; k++) {
          dp[j][k] += dp[j - 1][k - i];
          dp[j][k] %= 100000;
        }
      }
    }
    cout << dp[N * N][S] << endl;
  }
  return 0;
}


Error: WA

Fixed submission:


// y09-6 ビンゴ(2回目)
#include <algorithm>
#include <cassert>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
#define LL long long
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define LL_MIN -9223372036854775808
#define LL_MAX 9223372036854775807
#define segment_size 65536
#define ROOP() while (true)

int main() {
  ROOP() {
    int N, M, S;
    cin >> N >> M >> S;
    if (N == 0)
      return 0;

    int dp[50][3001];
    for (int i = 0; i < 50; i++) {
      for (int j = 0; j < 3001; j++) {
        dp[i][j] = 0;
      }
    }
    dp[0][0] = 1;

    for (int i = 1; i <= M; i++) {
      for (int j = N * N; j >= 1; j--) {
        for (int k = i; k <= S; k++) {
          dp[j][k] += dp[j - 1][k - i];
          dp[i][k] %= 100000;
        }
      }
    }
    cout << dp[N * N][S] << endl;
  }
  return 0;
}
Problem p00460 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
using Int = long long;

template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T> vector<vector<T>> make_v(size_t a, size_t b) {
  return vector<vector<T>>(a, make_v<T>(b));
}
template <typename T>
vector<vector<vector<T>>> make_v(size_t a, size_t b, size_t c) {
  return vector<vector<vector<T>>>(a, make_v<T>(b, c));
}

template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) {
  t = v;
}

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) {
  for (auto &e : t)
    fill_v(e, v);
}

// INSERT ABOVE HERE
signed main() {
  Int n, m, s;
  while (cin >> n >> m >> s, n) {
    const Int MOD = 100000;
    int v = n * n;
    m -= v;
    s -= v * (v + 1) / 2;

    auto dp = make_v<int>(s + 1, m + 1);
    fill_v(dp, 0);
    dp[0][0] = 1;

    for (int i = 0; i < v; i++) {
      int c = v - i;
      auto nx = make_v<int>(s + 1, m + 1);
      fill_v(nx, 0);
      for (int j = 0; j <= s; j++) {
        for (int k = 0; k <= m; k++) {
          nx[j][k] += dp[j][k];
          nx[j][k] %= MOD;
          if (j + c <= s && k + 1 <= m) {
            dp[j + c][k + 1] += dp[j][k];
            dp[j + c][k + 1] %= MOD;
          }
        }
      }
      swap(dp, nx);
    }

    int ans = 0;
    for (int i = 0; i <= m; i++) {
      ans += dp[s][i];
      ans %= MOD;
    }
    cout << ans << endl;
  }
  return 0;
}


Error: MLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using Int = long long;

template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T> vector<vector<T>> make_v(size_t a, size_t b) {
  return vector<vector<T>>(a, make_v<T>(b));
}
template <typename T>
vector<vector<vector<T>>> make_v(size_t a, size_t b, size_t c) {
  return vector<vector<vector<T>>>(a, make_v<T>(b, c));
}

template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) {
  t = v;
}

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) {
  for (auto &e : t)
    fill_v(e, v);
}

// INSERT ABOVE HERE
signed main() {
  Int n, m, s;
  while (cin >> n >> m >> s, n) {
    const Int MOD = 100000;
    int v = n * n;
    s -= v * (v + 1) / 2;
    m -= v;
    // cout<<n<<" "<<m<<" "<<s<<endl;
    auto dp = make_v<signed>(v + 1, s + 1, m + 1);
    fill_v(dp, 0);
    dp[0][0][0] = 1;
    for (int i = 0; i < v; i++) {
      int c = v - i;
      for (int j = 0; j <= s; j++) {
        for (int k = 0; k <= m; k++) {
          dp[i + 1][j][k] += dp[i][j][k];
          dp[i + 1][j][k] %= MOD;
          if (j + c <= s && k + 1 <= m) {
            dp[i][j + c][k + 1] += dp[i][j][k];
            dp[i][j + c][k + 1] %= MOD;
          }
        }
      }
    }
    int ans = 0;
    for (int i = 0; i <= m; i++) {
      ans += dp[v][s][i];
      ans %= MOD;
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p00460 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <iostream>
using namespace std;
typedef long long ll;
ll mod = 100000;
int N, M, S;

ll dp[50][3001];

void init() {
  for (int i = 0; i < 50; i++)
    for (int j = 0; j < 3001; j++)
      dp[i][j] = 0;
  dp[0][0] = 1;
}

int main() {
  while (1) {
    cin >> N >> M >> S;
    if (N == 0 && M == 0 && S == 0)
      break;
    init();
    for (int i = 1; i <= N * N; i++) {
      for (int j = 0; j <= S; j++) {
        if (j - i >= 0)
          dp[i][j] += dp[i - 1][j - i];
        if (j - i >= 0)
          dp[i][j] += dp[i][j - i];
        if (j - M - 1 >= 0)
          dp[i][j] += (mod - dp[i - 1][j - M - 1]);
        dp[i][j] %= mod;
      }
    }
    cout << dp[N * N][S] << endl;
  }
  return 0;
}

Error: MLE

Fixed submission:

#include <iostream>
using namespace std;
typedef long long ll;
ll mod = 100000;
ll N, M, S;

int dp[2001][50][3001];

ll solve(ll num, ll cnt, ll sum) {
  if (dp[num][cnt][sum] != -1)
    return dp[num][cnt][sum];
  if (cnt == 0)
    return (sum == 0 ? 1 : 0);
  ll res = 0;
  for (int i = num; i <= M; i++)
    res = (res + solve(i + 1, cnt - 1, sum - i)) % mod;
  dp[num][cnt][sum] = res;
  return res;
}

void init() {
  for (int i = 0; i < 2001; i++)
    for (int j = 0; j < 50; j++)
      for (int k = 0; k < 3001; k++)
        dp[i][j][k] = -1;
}

int main() {
  while (1) {
    cin >> N >> M >> S;
    if (N == 0 && M == 0 && S == 0)
      break;
    init();
    cout << solve(1, N * N, S) << endl;
  }
  return 0;
}
Problem p00460 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
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 * n;

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

    for (int i = 0; i < n; i++) {
      int cur = i & 1, nxt = 1 - cur;
      for (int j = 0; j <= m; j++) {
        for (int k = 0; k <= s; k++)
          dp[nxt][j][k] = 0;
      }

      for (int j = 0; j <= m; j++) {
        for (int k = 0; k <= s; k++) {
          if (dp[cur][j][k] == 0)
            continue;
          if (j < m) {
            (dp[cur][j + 1][k] += dp[cur][j][k]) %= mod;
            if (k + j + 1 <= s)
              (dp[nxt][j + 1][k + j + 1] += dp[cur][j][k]) %= mod;
          }
        }
      }
    }

    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;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

int dp[2][2001][3001];
const int mod = 100000;

int main() {
  int n, m, s;
  while (cin >> n >> m >> s, n) {
    n = n * n;

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

    for (int i = 0; i < n; i++) {
      int cur = i & 1, nxt = 1 - cur;
      for (int j = 0; j <= m; j++) {
        for (int k = 0; k <= s; k++)
          dp[nxt][j][k] = 0;
      }

      for (int j = 0; j <= m; j++) {
        for (int k = 0; k <= s; k++) {
          if (j < m) {
            (dp[cur][j + 1][k] += dp[cur][j][k]) %= mod;
            if (k + j + 1 <= s)
              (dp[nxt][j + 1][k + j + 1] += dp[cur][j][k]) %= mod;
          }
        }
      }
    }

    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;
  }
}