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


#include <array>
#include <stdio.h>
#include <string.h>

using namespace std;

int n, m, s;

array<array<array<int, 3001>, 2001>, 2> memo;

int main() {
  for (;;) {
    scanf("%d %d %d", &n, &m, &s);
    if (n == 0)
      break;
    for (int i = 0; i <= n * n; ++i) {
      for (int j = 0; j <= m; ++j) {
        for (int k = 0; k <= s; ++k) {
          int ans = 0;
          if (i == 0) {
            if (j == 0 && k == 0)
              ans = 1;
            else
              ans = 0;
          } else {
            if (j <= 0 || k < j) {
              ans = 0;
            } else {
              ans = memo[(i - 1) % 2][j - 1][k - j] + memo[i % 2][j - 1][k - 1];
            }
          }
          memo[i % 2][j][k] = ans % 100000;
        }
      }
    }
    int ans = 0;
    for (int i = 0; i <= m; ++i) {
      ans += memo[(n * n) % 2][i][s];
      ans %= 100000;
    }
    printf("%d\\n", ans);
  }
  return 0;
}

Error: MLE

Fixed submission:


#include <array>
#include <stdio.h>
#include <string.h>

using namespace std;

int n, m, s;

array<array<array<int, 3001>, 2001>, 50> memo;

int main() {
  for (;;) {
    scanf("%d %d %d", &n, &m, &s);
    if (n == 0)
      break;
    for (int i = 0; i <= n * n; ++i) {
      for (int j = 0; j <= m; ++j) {
        for (int k = 0; k <= s; ++k) {
          int ans = 0;
          if (i == 0) {
            if (j == 0 && k == 0)
              ans = 1;
            else
              ans = 0;
          } else {
            if (j <= 0 || k < j) {
              ans = 0;
            } else {
              ans = memo[i - 1][j - 1][k - j] + memo[i][j - 1][k - 1];
            }
          }
          memo[i][j][k] = ans % 100000;
        }
      }
    }
    int ans = 0;
    for (int i = 0; i <= m; ++i) {
      ans += memo[n * n][i][s];
    }
    printf("%d\\n", ans);
  }
  return 0;
}
Problem p00460 (C++) — buggy submission, verdict: Time Limit Exceeded

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

constexpr int MOD = (int)1e5;

constexpr int MAX_S = 3000;

int n, m, s;

int dp[50][MAX_S + 1];

int main() {

  while (std::cin >> n >> m >> s, n + m + s) {

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

    dp[0][0] = 1;

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

    std::cout << dp[n * n][s] << std::endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

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

constexpr int MOD = (int)1e5;

constexpr int MAX_M = 2000, MAX_S = 3000;

int n, m, s;

int dp[2][MAX_M + 1][MAX_S + 1];

int main() {

  while (1) {

    std::cin >> n >> m >> s;

    if (n + m + s == 0)
      break;

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

    for (int i = 1; i <= std::min(m, s); ++i)
      dp[1][i][i] = 1;

    for (int i = 2; i <= n * n; ++i) {
      for (int j = 1; j <= std::min(m, s); ++j) {
        for (int k = j; k <= s; ++k) {
          for (int l = 1; l < j; ++l) {
            dp[i % 2][j][k] += dp[(i - 1) % 2][l][k - j];
            dp[i % 2][j][k] %= MOD;
          }
        }
      }
      std::memset(dp[(i - 1) % 2], 0, sizeof(dp[(i - 1) % 2]));
    }

    int ans = 0;

    for (int i = 1; i <= std::min(m, s); ++i)
      ans = (ans + dp[(n * n) % 2][i][s]) % MOD;

    std::cout << ans << std::endl;
  }

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

#include <bits/stdc++.h>

using namespace std;
constexpr int mod = 100000;
constexpr int MAX_N = 50;
constexpr int MAX_S = 3010;
constexpr int MAX_M = 2010;
typedef long long LL;
int main() {
  int N[5], M[5], S[5];
  int ret[5];
  LL dp[MAX_S][MAX_N];
  vector<int> query[MAX_M];
  int q = 0;
  for (q = 0;; q++) {
    scanf("%d%d%d", N + q, M + q, S + q);
    if (N[q] + M[q] + S[q] == 0)
      break;
    query[M[q]].push_back(q);
  }
  for (int i = 0; i < MAX_S; i++)
    for (int j = 0; j < MAX_N; j++)
      dp[i][j] = 0;
  dp[0][0] = 1;
  for (int i = 1; i < MAX_M; i++) {
    for (int j = MAX_S - 1; j >= i; j--)
      for (int k = 1; k < MAX_N; k++) {
        dp[j][k] += dp[j - i][k - 1];
        if (dp[j][k] >= mod)
          dp[j][k] -= mod;
      }
    for (auto &id : query[i])
      ret[id] = (int)dp[S[id]][N[id] * N[id]];
  }
  for (int i = 0; i < q; i++)
    printf("%d\\n", ret[i]);
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
constexpr int mod = 100000;
typedef long long LL;
int main() {
  int N, M, S;
  while (1) {
    scanf("%d%d%d", &N, &M, &S);
    if (N + M + S == 0)
      break;
    vector<vector<LL>> dp(S + 1, vector<LL>(M + 1, 0));
    dp[0][0] = 1;
    for (int i = 0; i < N * N; i++) {
      vector<vector<LL>> nxt(S + 1, vector<LL>(M + 1, 0));
      for (int j = 0; j <= S; j++)
        for (int k = 1; k <= M; k++)
          dp[j][k] = (dp[j][k] + dp[j][k - 1]) % mod;
      for (int k = 1; k <= M; k++)
        for (int j = k; j <= S; j++)
          nxt[j][k] = (nxt[j][k] + dp[j - k][k - 1]) % mod;
      swap(dp, nxt);
    }
    LL ret = 0;
    for (int i = 1; i <= M; i++)
      ret += dp[S][i];
    ret %= mod;
    printf("%d\\n", (int)ret);
  }
  return 0;
}
Problem p00460 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <cstring>
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 >= 1; j--)
        for (int k = i; k <= s; k++) {
          dp[j][k] += dp[j - 1][k - i];
          if (dp[j][k] >= 100000)
            dp[j][k] -= 100000;
        }
    printf("%d\\n", dp[n * n][s]);
  }
}

Error: WA

Fixed submission:

#include <cstdio>
#include <cstring>
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 >= 1; j--)
        for (int k = 1; k <= s; k++) {
          dp[j][k] += dp[j - 1][k - i];
          if (dp[j][k] >= 100000)
            dp[j][k] -= 100000;
        }
    printf("%d\\n", dp[n * n][s]);
  }
}
Problem p00460 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <iostream>
using namespace std;

int dp[2][59][3010];
int main() {
  int N, M, S, n2, ii, io;
  while (1) {
    cin >> N >> M >> S;
    if (N == 0 && M == 0 && S == 0)
      break;
    n2 = N * N;
    for (int j = 0; j <= n2; j++) {
      for (int k = 0; k <= S; k++) {
        dp[0][j][k] = 0;
      }
    }
    dp[0][0][0] = 1;
    for (int i = 1; i <= M; i++) {
      // for(int k=0;k<=n2;k++){//
      //	for(int j=0;j<=S;j++){//
      //		cout<<dp[i-1][k][j]<<" ";//
      //	}//
      //	cout<<endl;//
      // }//
      // cout<<endl;//
      if (i % 2) {
        ii = 0;
        io = 1;
      } else {
        ii = 1;
        io = 0;
      }

      for (int j = 0; j <= n2; j++) {
        for (int k = 0; k <= S; k++) {
          dp[io][j][k] = 0;
        }
      }
      for (int j = 0; j <= n2; j++) {
        for (int k = 0; k <= S; k++) {
          if (dp[ii][j][k] != 0) {
            if (k <= S - i && j != n2) {
              dp[io][j + 1][k + i] += dp[ii][j][k];
              dp[io][j + 1][k + i] %= 100000;
            }
            dp[io][j][k] += dp[ii][j][k];
            dp[io][j][k] %= 100000;
          }
        }
      }
    }

    // for(int i=0;i<=n2;i++){//
    //	for(int j=0;j<=S;j++){//
    //		cout<<dp[M][i][j]<<" ";//
    //	}//
    //	cout<<endl;//
    // }//

    cout << dp[M % 2][n2][S] << endl;
  }
  return 0;
}

Error: MLE

Fixed submission:

#include <iostream>
using namespace std;

int dp[2010][59][3010]; // n2,s
int main() {
  int N, M, S, n2;
  while (1) {
    cin >> N >> M >> S;
    if (N == 0 && M == 0 && S == 0)
      break;
    n2 = N * N;
    for (int k = 0; k <= M; k++) {
      for (int i = 0; i <= n2; i++) {
        for (int j = 0; j <= S; j++) {
          dp[k][i][j] = 0;
        }
      }
    }
    dp[0][0][0] = 1;
    for (int i = 1; i <= M; i++) {
      // for(int k=0;k<=n2;k++){//
      //	for(int j=0;j<=S;j++){//
      //		cout<<dp[i-1][k][j]<<" ";//
      //	}//
      //	cout<<endl;//
      // }//
      // cout<<endl;//
      for (int j = 0; j <= n2; j++) {
        for (int k = 0; k <= S; k++) {
          if (dp[i - 1][j][k] != 0) {
            if (k <= S - i && j != n2) {
              dp[i][j + 1][k + i] += dp[i - 1][j][k];
              dp[i][j + 1][k + i] %= 100000;
            }
            dp[i][j][k] += dp[i - 1][j][k];
            dp[i][j][k] %= 100000;
          }
        }
      }
    }

    // for(int i=0;i<=n2;i++){//
    //	for(int j=0;j<=S;j++){//
    //		cout<<dp[M][i][j]<<" ";//
    //	}//
    //	cout<<endl;//
    // }//

    cout << dp[M][n2][S] << endl;
  }
  return 0;
}
Problem p00460 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1e9;
const int mod = 100000;
int dp[2][3010][50];
int n, m, s;
int main() {
  while (1) {
    cin >> n >> m >> s;
    if (n == 0 && m == 0 && s == 0)
      break;
    memset(dp, 0, sizeof(dp));
    dp[0][0][0] = 1;
    for (int i = 1; i <= m; i++) {
      REP(j, 3010) REP(k, 50) dp[i & 1][j][k] = dp[(i - 1) & 1][j][k];
      for (int j = 0; j + i <= s; j++) {
        for (int k = 0; k < n * n; k++) {
          if (dp[(i - 1) & 1][j][k] >= 1) {
          }
          dp[i & 1][j + i][k + 1] += dp[(i - 1) & 1][j][k];
          dp[i & 1][j + i][k + 1] %= mod;
        }
      }
    }
    cout << dp[m & 1][s][n * n] % mod << endl;
  }
}

Error: MLE

Fixed submission:

#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1e9;
const int mod = 100000;
int dp[3000][2000][49];
int n, m, s;
/*int rec(int i,int j){
  cout<<i<<" "<<j<<endl;
  if(dp[i][j]!=-1)return dp[i][j];
  if(j==0)return dp[i][j]==1;
  if(i==0)return dp[i][j]=0;
  if(j<0)return 0;
  int res=0;
  for(int k=i;k>=1;k--){
    res+=rec(k-1,j-k);
    res%=mod;
  }
  return dp[i][j]=res%mod;
}*/
int main() {
  while (1) {
    cin >> n >> m >> s;
    if (n == 0 && m == 0 && s == 0)
      break;
    memset(dp, -1, sizeof(dp));
    // cout<<rec(n,s)%mod<<endl;
  }
}
Problem p00460 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
int N, M, S;
typedef long long int ll;
int DP[2001][3001];
int MOD = 100000;
int main() {
  while (true) {
    scanf("%d%d%d", &N, &M, &S);
    if (N == 0 && M == 0 && S == 0)
      break;
    for (int i = 0; i <= N * N; i++)
      for (int j = 0; j <= S; j++)
        DP[i][j] = 0;
    DP[0][0] = 1;
    for (int i = 1; i <= M; i++) {
      for (int j = S; j >= 0; j--) {
        if (j + i <= S) {
          for (int k = 1; k <= N * N; k++) {
            DP[k][j + i] = (DP[k][j + i] + DP[k - 1][j]) % MOD;
          }
        }
      }
    }
    int ans = 0;
    printf("%d\\n", DP[N * N][S] % MOD);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
int N, M, S;
int DP[2001][3001];
int DP1[2001][3001];
const int MOD = 100000;
int main() {
  while (true) {
    scanf("%d%d%d", &N, &M, &S);
    if (N == 0 && M == 0 && S == 0)
      break;
    for (int j = 1; j <= min(M, S); j++)
      DP[j][j] = 1;
    for (int i = 1; i < N * N; i++) {
      for (int j = 1; j <= M; j++) {
        for (int k = 1; k <= S; k++)
          DP1[j][k] = 0;
      }
      for (int j = 1; j <= M; j++) {
        for (int k = 1; k <= S; k++) {
          if (DP[j][k] == 0)
            continue;
          for (int l = j + 1; (k + l <= S) && (l <= M); l++) {
            DP1[l][k + l] += DP[j][k];
            DP1[l][k + l] %= MOD;
          }
        }
      }

      for (int j = 1; j <= M; j++) {
        for (int k = 1; k <= S; k++) {
          DP[j][k] = DP1[j][k];
        }
      }
    }
    int ans = 0;
    for (int j = 1; j <= M; j++) {
      for (int k = S; k <= S; k++) {
        ans += DP[j][k];
        ans %= MOD;
      }
    }
    printf("%d\\n", ans);
  }
  return 0;
}
Problem p00460 (C++) — buggy submission, verdict: Memory Limit Exceeded

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

#define MOD 100000
int N, M, S;
int dp[2][2001][2001];
int T[2001][2001];

int main() {
  while (cin >> N >> M >> S) {
    if (N == 0 && M == 0 && S == 0)
      break;
    for (int j = 1; j <= M; j++) {
      for (int k = 1; k <= S; k++) {
        dp[0][j][k] = 0;
      }
    }

    N *= N;
    S -= N * (N + 1) / 2;
    M = min(M - N, S);
    for (int i = 0; i <= M; i++)
      dp[0][i][i] = 1;

    for (int i = 0; i < N - 1; i++) {
      int _ = i % 2;
      for (int j = 0; j <= M; j++) {
        for (int k = 0; k <= S; k++) {
          dp[_ ^ 1][j][k] = 0;
          T[j][k] = 0;
        }
      }
      for (int j = 0; j <= M; j++) {
        for (int k = 0; k <= S; k++) {
          if (j + k <= S) {
            T[j][j + k] = (T[j][j + k] + dp[_][j][k]) % MOD;
          }
        }
      }
      for (int j = 0; j <= M; j++) {
        for (int k = 0; k <= S; k++) {
          if (j > 0 && k > 0)
            T[j][k] = (T[j][k] + T[j - 1][k - 1]) % MOD;
          dp[_ ^ 1][j][k] = (dp[_ ^ 1][j][k] + T[j][k]) % MOD;
        }
      }
    }
    int m = 0;
    for (int i = 0; i <= M; i++)
      m = (m + dp[(N - 1) % 2][i][S]) % MOD;
    cout << m << "\\n";
  }
  return 0;
}

Error: MLE

Fixed submission:

#include <cstdio>
using namespace std;

#define MOD 100000
int N, M, S;
int dp[2][2001][3001];
int T[2001][3001];

int main() {
  while (scanf("%d %d %d", &N, &M, &S)) {
    if (N == 0 && M == 0 && S == 0)
      break;
    for (int j = 1; j <= M; j++) {
      for (int k = 1; k <= S; k++) {
        dp[0][j][k] = 0;
      }
    }
    int mm = M > S ? S : M;
    for (int i = 1; i <= mm; i++)
      dp[0][i][i] = 1;
    for (int i = 0; i < N * N - 1; i++) {
      int crnt = i % 2, next = (i + 1) % 2;
      for (int j = 1; j <= mm; j++) {
        for (int k = 1; k <= S; k++) {
          dp[next][j][k] = 0;
          T[j][k] = 0;
        }
      }
      for (int j = i + 1; j <= mm; j++) {
        for (int k = (i * (i - 1) / 2) + j; k <= S; k++) {
          if (dp[crnt][j][k] == 0)
            continue;
          int lb = j + 1;
          if (k + lb <= S) {
            T[lb][k + lb] = (T[lb][k + lb] + dp[crnt][j][k]) % MOD;
          }
        }
      }
      for (int j = 1; j <= mm; j++) {
        for (int k = 1; k <= S; k++) {
          T[j][k] = (T[j][k] + T[j - 1][k - 1]) % MOD;
          dp[next][j][k] = (dp[next][j][k] + T[j][k]) % MOD;
        }
      }
    }
    int m = 0;
    for (int i = N; i <= mm; i++)
      m = (m + dp[(N * N - 1) % 2][i][S]) % MOD;
    printf("%d\\n", m);
  }
  return 0;
}
Problem p00460 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define LL long long
#define rep(i, n) for (int i = 0; i < n; ++i)
#define per(i, n) for (int i = n; i > 0; i--)
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define ROF(i, a, b)                                                           \\
  for (int i = a; i >= b; i--)                                                 \\
    ;
#define push_back PB;
#define pop_back PPB;
using namespace std;
static const LL INF = 1LL << 61LL;
static const double EPS = 1e-8;
static const int mod = 100000;
typedef pair<int, int> PII;

LL dp[51][3001];

int main() {
  while (1) {
    LL N, M, S;
    cin >> N >> M >> S;
    if (N == 0 && M == 0 && S == 0)
      break;
    N *= N;
    memset(dp, 0, sizeof(dp));
    dp[0][0] = 1;
    FOR(i, 1, M) {
      per(j, N) {
        FOR(k, i, S) { dp[j][k] += (mod + dp[j - 1][k - i]) % mod; }
      }
    }
    cout << dp[N][S] % mod << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define LL long long
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define push_back PB;
#define pop_back PPB;
using namespace std;
static const LL INF = 1LL << 61LL;
static const double EPS = 1e-8;
static const int mod = 100000;
typedef pair<int, int> PII;

int N, M, S;
int mem[51][3000];
int V;

LL Series(int n, int sum, int mx) {
  int p = n * V + sum;
  if (p == S) {
    // cout<<sum<<" "<<p<<" "<<V<<" "<<mx<<endl;
    return 1;
  } else
    return 0;
}

LL cal(int n, int sum, int mx) {
  LL res = 0;
  if (mem[n][sum] != -1)
    return mem[n][sum];
  if (n == N * N) {
    return Series(n, sum, mx);
  }
  FOR(i, 1, M) {
    int temp = S - sum + i * (N * N - n);
    // cout<<temp<<endl;
    if (temp < 0)
      break;
    res += cal(n + 1, sum + i * (N * N - n), mx + i);
  }
  return mem[n][sum] = res % mod;
}

int main() {
  LL ans = 0;
  while (1) {
    cin >> N >> M >> S;
    if (N == 0 && M == 0 && S == 0)
      break;
    FOR(i, 1, M) {
      memset(mem, -1, sizeof(mem));
      V = i;
      ans += cal(1, 0, V);
    }
    cout << ans % mod << endl;
    ans = 0;
  }
  return 0;
}
Problem p00460 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <cstring>
#define mod 100000
int n, m, s;
int dp[3001][50];
int main() {
  while (scanf("%d%d%d", &n, &m, &s)) {
    if (!n && !m && !s)
      break;
    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 k = s; k >= i; k--) {
          dp[k][j] = (dp[k][j] + dp[k - i][j - 1]) % mod;
        }
      }
    }
    printf("%d\\n", dp[s][n * n]);
  }
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <cstring>
#define mod 100000
typedef long long ll;
ll dp[3001][50];
int main() {
  int n, m, s;
  while (scanf("%d%d%d", &n, &m, &s)) {
    if (!n && !m && !s)
      break;
    for (int i = 0; i <= n * n; i++)
      for (int j = 0; j <= s; j++)
        dp[i][j] = 0;
    dp[0][0] = 1;
    for (int i = 1; i <= m; i++) {
      for (int j = n * n; j > 0; j--) {
        for (int k = 1; k <= s; k++) {
          if (k >= i)
            dp[k][j] += dp[k - i][j - 1] % mod;
        }
      }
    }
    printf("%lld\\n", dp[s][n * n] % mod);
  }
}
Problem p00460 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int dp[10][55][3010] = {0};
int main() {
  int N, M, S;
  while (scanf("%d%d%d", &N, &M, &S), N + M + S) {
    for (int i = 1; i < N * N + 1; i++) {
      for (int j = 1; j < S + 1; j++) {
        dp[0][i][j] = 0;
      }
    }
    for (int i = 1; i < M + 1; i++) {
      for (int j = 1; j < N * N + 1; j++) {
        for (int k = 1; k < S + 1; k++) {
          dp[1][j][k] = 0;
          if (j == 1) {
            dp[1][j][k] = dp[0][j][k];
            if (i == k)
              dp[1][j][k]++;
          } else {
            dp[1][j][k] = dp[0][j][k];
            if (k > i)
              dp[1][j][k] = (dp[1][j][k] + dp[0][j - 1][k - i]) % 100000;
          }
        }
      }
      for (int j = 1; j < N * N + 1; j++) {
        for (int k = 1; k < S + 1; k++) {
          dp[0][j][k] = dp[1][j][k];
          dp[1][j][k] = 0;
        }
      }
    }
    printf("%d\\n", dp[0][N * N][S]);
  }
  return 0;
}

Error: MLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int dp[55][2010][3010] = {0};
int main() {
  int N, M, S;
  while (scanf("%d%d%d", &N, &M, &S), N + M + S) {
    for (int i = 1; i < N * N + 1; i++) {
      for (int j = 1; j < M + 1; j++) {
        for (int k = 1; k < S + 1; k++) {
          dp[i][j][k] = 0;
          if (i == 1) {
            dp[i][j][k] = dp[i][j - 1][k];
            if (j == k)
              dp[i][j][k]++;
          } else {
            dp[i][j][k] = dp[i][j - 1][k];
            if (k > j)
              dp[i][j][k] = (dp[i][j][k] + dp[i - 1][j - 1][k - j]) % 100000;
          }
        }
      }
    }
    printf("%d\\n", dp[N * N][M][S]);
  }
  return 0;
}
Problem p00460 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> P1;
typedef pair<P, P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
long long dp[3001][50];
int n, m, s;
int main() {
  while (1) {
    memset(dp, 0, sizeof(dp));
    scanf("%d %d %d", &n, &m, &s);
    if (!n)
      break;
    dp[0][0] = 1;
    for (int i = 1; i <= m; i++) {
      for (int j = n * n; j >= 0; j--) {
        for (int k = i; k <= s; k++) {
          dp[k][j] += dp[k - i][j - 1];
          dp[k][j] %= 100000;
        }
      }
    }
    printf("%d\\n", dp[s][n * n]);
  }
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <cstdio>
using namespace std;
int n, m, s;
int d[501][50][501] = {};
int dp(int a, int b, int c) {
  if (a <= 500 && c <= 500) {
    if (d[a][b][c]) {
      return d[a][b][c];
    }
  }
  if (a <= 0 && b != n * n) {
    return 0;
  }
  if (c > m - (n * n - b)) {
    return 0;
  }
  if (b > n * n) {
    return 0;
  }
  int ans = 0;
  for (int i = c + 1; i <= a; i++) {
    ans += (dp(a - i, b + 1, i)) % 100000;
    ans %= 100000;
  }
  if (a <= 500 && c <= 500)
    d[a][b][c] = ans % 100000;
  return ans % 100000;
}
int main() {
  while (1) {
    scanf("%d %d %d", &n, &m, &s);
    printf("%d\\n", dp(s, 0, 0));
  }
}
Problem p00460 (C++) — buggy submission, verdict: Memory Limit Exceeded

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

int dp[2][2000][3000];
signed main() {
  int a, b, c;
  while (cin >> a >> b >> c, a || b || c) {
    a *= a;
    c -= a * (a + 1) / 2;
    b -= a;
    memset(dp, 0, sizeof(dp));
    dp[0][0][0] = 1;
    for (int d = 1; d <= a; d++) {
      memset(dp[d & 1], 0, sizeof(dp[d & 1]));
      for (int e = 0; e <= b; e++) {
        for (int f = 0; f <= c; f++) {
          dp[d & 1][e][f] = dp[(d + 1) & 1][e][f];
          if (e >= 1 && f >= (a - d + 1)) {
            dp[d & 1][e][f] =
                (dp[d & 1][e][f] + dp[d & 1][e - 1][f - (a - d + 1)]) % 100000;
          }
        }
      }
    }
    int sum = 0;
    for (int i = 0; i <= b; i++) {
      sum = (sum + dp[a & 1][i][c]) % 100000;
    }
    cout << sum << endl;
  }
}

Error: MLE

Fixed submission:

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

int dp[2][2000][3000];
signed main() {
  int a, b, c;
  while (cin >> a >> b >> c, a || b || c) {
    a *= a;
    c -= a * (a + 1) / 2;
    b -= a;
    memset(dp, 0, sizeof(dp));
    dp[0][0][0] = 1;
    for (int d = 1; d <= a; d++) {
      memset(dp[d & 1], 0, sizeof(dp[d & 1]));
      for (int e = 0; e <= b; e++) {
        for (int f = 0; f <= c; f++) {
          dp[d & 1][e][f] = dp[(d + 1) & 1][e][f];
          if (e >= 1 && f >= (a - d + 1)) {
            dp[d & 1][e][f] =
                (dp[d & 1][e][f] + dp[d & 1][e - 1][f - (a - d + 1)]) % 100000;
          }
        }
      }
    }
    int sum = 0;
    for (int i = 0; i <= b; i++) {
      sum += dp[a & 1][i][c] % 100000;
    }
    cout << sum << endl;
  }
}