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

#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
#define mod 100000
int dp[50][3001];
int main() {
  int n, m, s;
  while (scanf("%d%d%d", &n, &m, &s), (n | m | s)) {

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

    dp[0][0] = 1;

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

    /*for(int i = 0; i < n*n+1; i++){
            for(int j = 0; j < s+1;j++){
                    printf("%3d",dp[i][j]);
            }
            puts("");
    }*/

    printf("%d\\n", dp[n * n][s]);
  }
  return 0;
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
#define mod 100000
int dp[50][2001][3001];
int main() {
  int n, m, s;
  while (scanf("%d%d%d", &n, &m, &s), (n | m | s)) {
    //      memset(dp,0,sizeof(dp));
    for (int i = 0; i < n * n + 1; i++)
      for (int j = 0; j < m + 1; j++)
        for (int k = 0; k < s + 1; k++)
          dp[i][j][k] = 0;
    for (int i = 1; i < m + 1; i++) {
      for (int j = 1; j < i + 1; j++) {
        dp[1][i][j] = 1;
      }
    }
    m++;
    s++;
    for (int i = 2; i < n * n + 1; i++) {
      for (int j = 1; j < m; j++) {
        for (int k = 1; k < s; k++) {
          dp[i][j][k] += dp[i][j - 1][k];
          if (k >= j) {
            dp[i][j][k] += dp[i - 1][j - 1][k - j];
            dp[i][j][k] %= mod;
          }
          dp[i][j][k] %= mod;
        }
      }
    }
    printf("%d\\n", dp[n * n][m - 1][s - 1] % mod);
  }
  return 0;
}
Problem p00460 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <stdio.h>
int dp[50][3001];
int main() {
  int n, m, s;
  int i, j, k;
  while (1) {
    scanf("%d %d %d", &n, &m, &s);
    if (n == 0)
      return 0;
    for (i = 0; i <= n * n; i++)
      for (j = 0; j <= s; j++)
        dp[i][j] = 0;
    dp[0][0] = 1;
    for (i = 1; i <= m; i++) {
      for (j = s; j >= 0; j--) {
        if (j + i <= s) {
          for (k = 0; k < n * n; k++) {
            dp[k + 1][j + i] = (dp[k + 1][j + i] + dp[k][j]) % 100000;
          }
        }
      }
    }
    printf("%d\\n", dp[n * n][s]);
  }
}

Error: MLE

Fixed submission:

#include <stdio.h>
typedef long long ll;
int dp[2][2001][3001];
int min(int a, int b) { return a < b ? a : b; }
int main() {
  int n, m, s;
  int i, j, k, l;
  while (1) {
    scanf("%d %d %d", &n, &m, &s);
    if (n == 0)
      return 0;
    for (i = 0; i <= m; i++)
      for (j = 0; j <= s; j++)
        dp[1][i][j] = 0;
    dp[1][0][0] = 1;
    for (i = 0; i < n * n; i++) {
      for (j = 0; j <= m; j++)
        for (k = 0; k <= s; k++)
          dp[i % 2][j][k] = 0;
      for (j = (i + 1) * (i + 2) / 2; j <= s; j++) {
        int u;
        if (i == n * n - 1)
          u = m;
        else
          u = min(m, (s - j) / (n * n - i - 1) - (n * n - i) / 2);
        for (k = i; k < u; k++) {
          for (l = k + 1; l <= u; l++) {
            if (j >= l)
              dp[i % 2][l][j] =
                  (dp[i % 2][l][j] + dp[(i + 1) % 2][k][j - l]) % 100000;
          }
        }
      }
    }
    int ans = 0;
    for (i = n; i <= m; i++)
      ans = (ans + dp[(n * n - 1) % 2][i][s]) % 100000;
    printf("%d\\n", ans);
  }
}
Problem p00460 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include "bits/stdc++.h"
main() {
  for (int n, m, s, i, j, d[50][3500], M = 1e5;
       std::cin >> n >> m >> s, n *= n;) {
    std::fill(d[0], d[50], M);
    d[0][0] = 1;
    for (i = 1; i <= n; ++i)
      for (j = 0; j <= s; ++j) {
        if (j >= i)
          d[i][j] += d[i - 1][j - i] + d[i][j - i];
        if (j > m)
          d[i][j] -= d[i - 1][j - m - 1];
        d[i][j] %= M;
      }
    printf("%d\\n", d[n][s]);
  }
}

Error: MLE

Fixed submission:

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

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

int dp[50][2010][3100];

int dfs(int i = 0, int pre = 0, int sum = s) {
  if (sum < 0)
    return 0;
  if (pre > m)
    return 0;

  if (i == n * n) {
    return sum == 0;
  }

  int &ret = dp[i][pre][sum];

  if (ret != -1)
    return ret;
  ret = 0;
  for (int j = pre + 1; j <= m; j++) {
    ret += dfs(i + 1, j, sum - j);
    ret %= mod;
  }
  return ret;
}

signed main() {
  while (cin >> n >> m >> s, n) {
    memset(dp, -1, sizeof(dp));

    cout << dfs() << endl;
  }
}
Problem p00460 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;

#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(n) rep(i, n)
#define all(n) n.begin(), n.end()

const int MAXN = 7, MAXS = 3000;
int n, m, s;
unsigned int dp[MAXN * MAXN + 2][MAXS + 10], UB = 100000;

int main() {

  while (cin >> n >> m >> s && n) {
    memset(dp, 0, sizeof(dp));
    dp[0][0] = 1;

    for (int i_m = 1; i_m <= m; i_m++)
      for (int i_n = n * n + 1; i_n > 0; i_n--)
        for (int i_s = s; i_s > 0; i_s--)
          if (i_s - i_m >= 0)
            dp[i_n][i_s] = (dp[i_n][i_s] + dp[i_n - 1][i_s - i_m]) % UB;

    // rep(i,n*n){rep(j,s) cout << dp[i][j] << ","; cout << endl;}

    cout << dp[n * n][s] << endl;
  }
  return 0;
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;

#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(n) rep(i, n)
#define all(n) n.begin(), n.end()

const int MAXN = 7, MAXM = 2010, MAXS = 3000;
int n, m, s;
unsigned int dp[MAXN * MAXN + 2][MAXM + 10][MAXS + 10], UB = 100000;

int main() {
  memset(dp, 0, sizeof(dp));
  rep(i_m, MAXM + 1) dp[0][i_m][0] = 1;
  // dp[0][0][0] = 1;

  rep(i_n, MAXN * MAXN + 1) rep(i_m, MAXM + 1)
      rep(i_s, MAXS + 1) if (i_s - (i_m + 1) > -1) dp[i_n + 1][i_m + 1][i_s] =
          (dp[i_n + 1][i_m][i_s] + dp[i_n][i_m][i_s - (i_m + 1)]) % UB;
  else dp[i_n + 1][i_m + 1][i_s] = dp[i_n + 1][i_m][i_s];

  while (cin >> n >> m >> s && n)
    cout << dp[n * n][m][s] << endl;

  return 0;
}
Problem p00460 (C++) — buggy submission, verdict: Runtime Error

#include "bits/stdc++.h"

using namespace std;

typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)

int dp[2][2300][3300];

int main() {
  int n, m, s;
  while (cin >> n >> m >> s) {
    if (n == 0 && m == 0 && s == 0)
      break;

    rep(i, 2) rep(j, 2300) rep(k, 3300) dp[i][j][k] = 0;
    dp[0][0][0] = 1;

    for (int i = 1; i <= n * n; i++) {
      for (int j = 0; j < 2300; j++)
        for (int k = 0; k < 3300; k++)
          dp[i % 2][j][k] = 0;
      for (int j = 1; j <= m; j++) {
        for (int k = 1; k <= s; k++) {
          if (k - j >= 0) {
            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;
          }
        }
      }
    }

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

Error: -11

Fixed submission:

#include "bits/stdc++.h"

using namespace std;

typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)

int main() {
  int n, m, s;
  while (cin >> n >> m >> s) {
    if (n == 0 && m == 0 && s == 0)
      break;

    int dp[2][2300][3300];

    rep(i, 2) rep(j, 2300) rep(k, 3300) dp[i][j][k] = 0;
    dp[0][0][0] = 1;

    for (int i = 1; i <= n * n; i++) {
      for (int j = 0; j < 2300; j++)
        for (int k = 0; k < 3300; k++)
          dp[i % 2][j][k] = 0;
      for (int j = 1; j <= m; j++) {
        for (int k = 1; k <= s; k++) {
          if (k - j >= 0) {
            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;
          }
        }
      }
    }

    ll ans = 0;
    for (int i = 0; i <= m; i++) {
      ans += dp[(n * n) % 2][i][s];
      ans %= 100000;
    }
    cout << ans << endl;
  }
}
Problem p00460 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <vector>

using namespace std;
#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define all(co) co.begin(), co.end()
const int INF = 1 << 29;

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

Error: -11

Fixed submission:

#include <algorithm>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <vector>

using namespace std;
#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define all(co) co.begin(), co.end()
const int INF = 1 << 29;

int dp[50][3001];
signed main() {
  int n, m, s;
  while (cin >> n >> m >> s && n) {
    n = n * n;
    memset(dp, 0, sizeof(dp));
    const int MOD = 100000;
    dp[0][0] = 1;
    for (int i = 1; i <= m; i++) {
      for (int j = n; j > 0; j++) {
        for (int k = i; k <= s; k++) {
          dp[j][k] += dp[j - 1][k - i];
          dp[j][k] %= MOD;
        }
      }
    }
    cout << dp[n][s] << endl;
  }
  return 0;
}
Problem p00460 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <vector>

#define rep(i, n) for (int i = 0; i < n; i++)
#define all(c) (c).begin(), (c).end()
#define mp make_pair
#define pb push_back
#define rp(i, c) rep(i, (c).size())
#define fr(i, c)                                                               \\
  for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define dbg(x) cerr << #x << " = " << (x) << endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
const int inf = 1 << 28;
const double INF = 1e12, EPS = 1e-9;

int n, m, s;
int dp[50][3001];

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

    rep(i, m) {
      for (int j = n * n; j > 0; j--)
        for (int k = s; k > n * n - j; k--) {
          dp[j][k] =
              dp[j - 1][k - (n * n - j + 1)] + dp[j][k - (n * n - j + 1)];
          if (dp[j][k] > 100000)
            dp[j][k] -= 100000;
        }
    }
    printf("%d\\n", dp[n * n][s]);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <vector>

#define rep(i, n) for (int i = 0; i < n; i++)
#define all(c) (c).begin(), (c).end()
#define mp make_pair
#define pb push_back
#define rp(i, c) rep(i, (c).size())
#define fr(i, c)                                                               \\
  for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define dbg(x) cerr << #x << " = " << (x) << endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
const int inf = 1 << 28;
const double INF = 1e12, EPS = 1e-9;

int n, m, s;
int dp[50][3001];

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

    rep(i, m) {
      for (int j = n * n; j > 0; j--)
        for (int k = s; k > n * n - j; k--)
          dp[j][k] =
              (dp[j - 1][k - (n * n - j + 1)] + dp[j][k - (n * n - j + 1)]) %
              100000;
    }
    printf("%d\\n", dp[n * n][s]);
  }
  return 0;
}
Problem p00460 (C++) — buggy submission, verdict: Memory Limit Exceeded

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

const int mod = 1e5;

int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  int N, M, S;
  while (cin >> N >> M >> S, N | M | S) {
    N *= N;
    vector<vector<int>> dp(S + 1, vector<int>(N + 1));
    dp[0][0] = 1;
    for (int i = 1; i <= M; i++) {
      auto tmp = dp;
      for (int j = 0; j + i <= S; j++) {
        for (int k = 0; k < N; k++) {
          (dp[j + i][k + 1] += tmp[j][k]) %= mod;
        }
      }
    }
    printf("%d\\n", dp[S][N]);
  }
  return 0;
}


Error: MLE

Fixed submission:

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

const int mod = 1e5;

int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  int N, M, S;
  while (cin >> N >> M >> S, N | M | S) {
    N *= N;
    vector<vector<vector<int>>> dp(
        M + 1, vector<vector<int>>(S + 1, vector<int>(N + 1)));
    dp[0][0][0] = 1;
    for (int i = 1; i <= M; i++) {
      dp[i] = dp[i - 1];
      for (int j = 0; j + i <= S; j++) {
        for (int k = 0; k < N; k++) {
          (dp[i][j + i][k + 1] += dp[i - 1][j][k]) %= mod;
        }
      }
    }
    printf("%d\\n", dp[M][S][N]);
  }
  return 0;
}
Problem p00460 (C++) — buggy submission, verdict: Time Limit Exceeded

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

const int MOD = 100000;
int n, m, s;
int dp[2][2001][3001];
int main() {
  while (cin >> n >> m >> s && n && m && s) {
    memset(dp, 0, sizeof dp);
    int ans = 0;
    dp[0][0][0] = 1;

    for (int i = 1; i <= n * 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]) % MOD;

      memset(dp[(i + 1) % 2], 0, sizeof dp[(i + 1) % 2]);
    }

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

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

const int MOD = 100000;
int n, m, s;
int dp[2][2001][3001];
int main() {
  while (cin >> n >> m >> s && n && m && s) {
    dp[0][0][0] = 1;

    for (int i = 0; i < n * n; i++) {

      for (int j = 0; j <= m; j++)
        for (int k = 0; k <= s; k++)
          if (dp[0][j][k])
            for (int lm = j + 1, ls = k + lm; lm <= m && ls <= s;
                 lm++, ls = k + lm)
              dp[1][lm][ls] = (dp[0][j][k] + dp[1][lm][ls]) % 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;
        }
      }
    }

    int ans = 0;
    for (int i = 0; i <= m; i++)
      ans = (ans + dp[0][i][s]) % MOD;
    cout << ans << endl;
  }
  return 0;
}
Problem p00460 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>

using namespace std;

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

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

int main() {

  int n, m, s, nn, st, i, j, k;
  int t1 = 0, t2 = 1;
  while (1) {
    scanf("%d%d%d", &n, &m, &s);
    if (n == 0)
      break;

    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) {
        nn = i;
        st = (nn * (nn + 1)) / 2;
        int mm, pp, end;
        mm = (j - 1) / 2;
        if (j % 2 == 0)
          pp = j / 2;
        else
          pp = 0;

        end = min(mm * (mm + 1) + pp + st, s + 1);

        for (k = st - 1; k <= end; 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<12){
                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: 0

Fixed submission:

#include <algorithm>
#include <cstdio>

using namespace std;

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

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

int main() {

  int n, m, s, nn, st, i, j, k;
  int t1 = 0, t2 = 1;
  while (1) {
    scanf("%d%d%d", &n, &m, &s);
    if (n == 0)
      break;

    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) {
        nn = i;
        st = (nn * (nn + 1)) / 2;
        int mm, pp, end;
        mm = (j - 1) / 2;
        if (j % 2 == 0)
          pp = j / 2;
        else
          pp = 0;

        end = mm * (mm + 1) + pp + st;

        for (k = st - 1; k <= end; 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<12){
                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]);
  }
}
Problem p00460 (C++) — buggy submission, verdict: Memory Limit Exceeded

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

int dp[50][3001];
int main() {
  int n, m, s;
  while (scanf("%d %d %d", &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; j > 0; --j) {
        for (int l = i; l <= s; ++l) {
          dp[j][l] = (dp[j][l] + dp[j - 1][l - i]) % 100000;
        }
      }
    }
    printf("%d\\n", dp[n * n][s]);
/*		for(int i=0; i<n*n; i++){
			for(int j=0; j<s; j++){
				printf("%d\\t", dp[i+1][j+1]);
			}
			printf("\\n");
		}
*/	}
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;

int n, m, s;
int dp[50][3001][2001];

int main() {
  while (1) {
    scanf("%d %d %d", &n, &m, &s);
    if (n == 0)
      break;
    memset(dp, 0, sizeof(dp));
    //		fill(dp[0][0], dp[49][0], 0);

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

    for (int i = 2; i < n * n + 1; i++) {
      for (int j = 3; j < s + 1; j++) {
        for (int k = 2; k < m + 1; k++) {
          if (j - k >= 1) {
            dp[i][j][k] += dp[i - 1][j - k][k - 1];
            dp[i][j][k] %= 100000;
          }
          dp[i][j][k] += dp[i][j][k - 1];
          dp[i][j][k] %= 100000;
        }
      }
    }
    /*
                    for(int i=0; i<n*n; i++){
                            printf("%d\\n", i);
                            for(int j=1; j<s+1; j++){
                                    for(int k=1; k<m+1; k++){
                                            printf("%d\\t", dp[i][j][k]);
                                    }
                                    printf("\\n");
                            }
                    }
    */
    printf("%d\\n", dp[n * n][s][m]);
  }
  return 0;
}
Problem p00460 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <assert.h>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <vector>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c)                                                           \\
  for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

int n, m, s;
const int MOD = 100000;
int dp[2010][3010];

int main() {
  while (scanf("%d %d %d", &n, &m, &s), n | m | s) {
    MEMSET(dp, 0);
    FOREQ(i, 0, m) { dp[i][0] = 1; }
    REP(iter, n * n) {
      dp[m][s] = 0;
      for (int i = m; i >= 1; i--) {
        FOREQ(j, 0, s - i) {
          if (i > (s - j) / (n * n - iter)) {
            break;
          }
          dp[i][j + i] = dp[i - 1][j];
        }
        REP(j, i) { dp[i][j] = 0; }
      }
      FOREQ(i, 1, m) {
        FOREQ(j, 0, s) {
          if (i > (s - j + i) / (n * n - iter)) {
            break;
          }
          dp[i][j] += dp[i - 1][j];
          dp[i][j] %= MOD;
        }
      }
      if (iter == 0) {
        FOREQ(i, 0, m) { dp[i][0] = 0; }
      }
    }
    printf("%d\\n", dp[m][s]);
  }
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <assert.h>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <vector>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c)                                                           \\
  for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

int n, m, s;
const int MOD = 100000;
int dp[2][2010][3010];

int main() {
  while (scanf("%d %d %d", &n, &m, &s) > 0) {
    MEMSET(dp, 0);
    FOREQ(i, 0, m) { dp[0][i][0] = 1; }
    REP(iter, n * n) {
      int prev = iter & 1;
      int next = prev ^ 1;
      MEMSET(dp[next], 0);
      FOREQ(i, 1, m) {
        FOREQ(j, 0, s - i) {
          if (i > (s - j) / (n * n - iter)) {
            break;
          }
          if (dp[prev][i - 1][j] == 0) {
            continue;
          }
          // assert(dp[next][i][j + i] == 0);
          dp[next][i][j + i] += dp[prev][i - 1][j];
        }
      }
      FOREQ(i, 1, m) {
        FOREQ(j, 0, s) {
          dp[next][i][j] += dp[next][i - 1][j];
          dp[next][i][j] %= MOD;
        }
      }
    }
    printf("%d\\n", dp[(n * n) & 1][m][s]);
  }
}