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

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

typedef long long ll;
#define rep(i, n) for (int(i) = 0; (i) < (int)(n); ++(i))
#define each(itr, c)                                                           \\
  for (__typeof(c.begin()) itr = c.begin(); itr != c.end(); ++itr)
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second

int m, n;
int f[90][90];
int dy[4] = {1, -1, 0, 0}, dx[4] = {0, 0, 1, -1};

inline bool in(int y, int x) { return (0 <= y && y < n && 0 <= x && x < m); }

//?????¨??????
int dfs(int y, int x) {
  int ret = 1;
  rep(i, 4) {
    int ny = y + dy[i], nx = x + dx[i];
    if (in(ny, nx) && f[ny][nx] == 1) {
      f[y][x] = 0;
      ret = max(ret, dfs(ny, nx) + 1);
      f[y][x] = 1;
    }
  }

  // printf(" %d,%d ret %d\\n", y,x,ret);
  return ret;
}

int main() {
  while (cin >> m >> n, m | n) {
    rep(i, n) rep(j, m) scanf(" %d", &f[i][j]);

    int ans = 0;
    rep(i, n) rep(j, m) {
      if (f[i][j] == 0)
        continue;
      // printf("start %d,%d\\n", i,j);
      ans = max(ans, dfs(i, j));
    }

    cout << ans << endl;
  }
  return 0;
}

Error: MLE

Fixed submission:

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

typedef long long ll;
#define rep(i, n) for (int(i) = 0; (i) < (int)(n); ++(i))
#define each(itr, c)                                                           \\
  for (__typeof(c.begin()) itr = c.begin(); itr != c.end(); ++itr)
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pi;
typedef pair<pi, vvi> P;

//?????¨????????¨?????£??????????????¶???????????£????°??????°????????§???
map<P, int> d;

int main() {
  int dy[4] = {1, -1, 0, 0}, dx[4] = {0, 0, 1, -1};

  int m, n;
  while (cin >> m >> n, m | n) {
    vvi f(m, vi(n));
    rep(i, m) rep(j, n) scanf(" %d", &f[i][j]);

    int ans = 0;

    //??????????????°???
    d.clear();
    rep(i, m) rep(j, n) {
      if (f[i][j] == 0)
        continue;

      vvi tf(f);
      tf[i][j] = 0;

      queue<P> que;
      que.push(P(pi(i, j), tf));
      d[P(pi(i, j), tf)] = 1;
      while (!que.empty()) {
        P now = que.front();
        que.pop();

        ans = max(ans, d[now]);

        rep(k, 4) {
          pi c = now.fi;
          vvi nf = now.se;

          int ny = c.fi + dy[k], nx = c.se + dx[k];
          if (0 <= ny && ny < m && 0 <= nx && nx < n) {
            if (nf[ny][nx] == 1) {
              nf[ny][nx] = 0;

              P next_state(pi(ny, nx), nf);
              if (d.find(next_state) == d.end()) {
                d[next_state] = d[now] + 1;
                que.push(next_state);
              } else {
                if (d[next_state] < d[now] + 1) {
                  d[next_state] = d[now] + 1;
                  que.push(next_state);
                }
              }
            }
          }
        }
      }
    }

    cout << ans << endl;
  }
  return 0;
}
Problem p00458 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int m, n;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
vector<vector<int>> v;

int dfs(int x, int y, int step) {
  int ans = step;
  for (int i = 0; i < 4; i++) {
    int nx = x + dx[i], ny = y + dy[i];
    if (0 <= nx && nx < n && 0 <= ny && ny < m && v[nx][ny] == 1) {
      v[nx][ny] = 0;
      ans = max(dfs(nx, ny, step + 1), ans);
      v[nx][ny] = 1;
    }
  }
  return ans;
}

int main() {
  while (cin >> m >> n, m || n) {
    v.clear();
    int ans = 0;

    for (int i = 0; i < n; i++) {
      vector<int> vv(m);
      for (int j = 0; j < m; j++) {
        scanf("%d", &vv[j]);
      }
      v.push_back(vv);
    }

    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        if (v[i][j] == 1) {
          v[i][j] = 0;
          ans = max(ans, dfs(i, j, 1));
          v[i][j] = 1;
        }
      }
    }
    cout << ans << endl;
  }
}

Error: TLE

Fixed submission:

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

int m, n;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int dfs(int x, int y, vector<vector<int>> field, int step) {
  int ans = step;
  for (int i = 0; i < 4; i++) {
    int nx = x + dx[i], ny = y + dy[i];
    if (0 <= nx && nx < n && 0 <= ny && ny < m && field[nx][ny] == 1) {
      field[nx][ny] = 0;
      ans = max(dfs(nx, ny, field, step + 1), ans);
      field[nx][ny] = 1;
    }
  }
  return ans;
}

int main() {
  while (cin >> m >> n, m || n) {
    vector<vector<int>> v;
    int ans = 0;

    for (int i = 0; i < n; i++) {
      vector<int> vv(m);
      for (int j = 0; j < m; j++) {
        scanf("%d", &vv[j]);
      }
      v.push_back(vv);
    }

    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        if (v[i][j] == 1) {
          v[i][j] = 0;
          ans = max(ans, dfs(i, j, v, 1));
          v[i][j] = 1;
        }
      }
    }
    cout << ans << endl;
  }
}
Problem p00458 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>

using namespace std;

int filde[90][90], dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
bool visit[90][90];
int m, n;

int count(int i, int j);

int main() {
  int ans;
  while (1) {
    cin >> m >> n;
    if (m == 0 && n == 0) {
      return 0;
    }
    for (int i = 0; i < m; i++) {
      for (int j = 0; j < n; j++) {
        cin >> filde[i][j];
      }
    }
    ans = -1;
    for (int i = 0; i < m; i++) {
      for (int j = 0; j < n; j++) {
        ans = max(ans, count(i, j));
      }
    }
    cout << ans << endl;
  }
}

int count(int i, int j) {
  visit[i][j] = true;
  int ans = 0;
  for (int k = 0; k < 4; k++) {
    if (filde[dx[k] + i][dy[k] + j] == 1 && 0 <= dx[k] + i && dx[k] + i <= m &&
        0 <= dy[k] + j && dy[k] + j <= n &&
        visit[dx[k] + i][dy[k] + j] == false) {
      ans = max(ans, count(dx[k] + i, dy[k] + j) + 1);
    }
  }
  visit[i][j] = false;
  return ans;
}

Error: 0

Fixed submission:

#include <iostream>
#include <queue>

using namespace std;

typedef pair<int, int> P;

int b[90][90];

void put(int a[90][90], int c, int d) {
  for (int i = 0; i < c; i++) {
    for (int j = 0; j < d; j++) {
      b[i][j] = a[i][j];
    }
  }
}

int count(int a, int b, int c, int d);

int main() {
  while (1) {
    int a[90][90], c, d, ans = 0, e;
    cin >> c >> d;
    if (c == 0 && d == 0) {
      return 0;
    }
    for (int i = 0; i < c; i++) {
      for (int j = 0; j < d; j++) {
        cin >> a[i][j];
      }
    }
    for (int i = 0; c * d != i + 1; i++) {
      for (int j = 0; j < c; j++) {
        put(a, c, d);
        for (int k = 0; k < d; k++) {
          if (a[i][j] == 0) {
            break;
          } else {
            b[i][j] = 0;
            e = count(i, j, c, d);
            if (ans <= e) {
              ans = e;
            }
          }
        }
      }
    }
    cout << ans << endl;
  }
}

int count(int a, int f, int c, int d) {
  int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
  P e;
  queue<P> Q;
  Q.push(P(a, f));
  int ans = 0;
  while (Q.size()) {
    e = Q.front();
    Q.pop();
    for (int i = 0; i < 4; i++) {
      if (0 <= e.first + dx[i] && e.first + dx[i] <= c &&
          0 <= e.second + dy[i] && e.second + dy[i] <= d) {
        if (b[e.first + dx[i]][e.second + dy[i]] == 1) {
          b[e.first + dx[i]][e.second + dy[i]] = 0;
          Q.push(P(e.first + dx[i], e.second + dy[i]));
        }
      }
    }
    ans++;
  }
  // cout << ans << endl;
  return ans;
}
Problem p00459 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
pair<int, int> a[11000], b[11000];
int sm, l;
int fi(int i, int p) {
  for (; sm < p; ++i)
    sm += a[i].second;
  if (sm > p) {
    copy_backward(a + i, a + l, a + l + 1);
    ++l;
    a[i - 1].second -= sm - p;
    a[i] = make_pair(a[i - 1].first + a[i - 1].second, sm - p);
    sm = p;
  }
  return i;
}
int main() {
  int i, j, k;
  int n;
  while (cin >> n, n) {
    int m, p, q, r;
    cin >> m >> p >> q >> r;
    if (r == n) {
      for (i = 0; i < m; ++i) {
        int x, y;
        cin >> x >> y;
      }
      cout << q - p + 1 << endl;
      continue;
    } else {
      a[0] = make_pair(1, r);
      a[1] = make_pair(r + 1, n - r);
      l = 2;
    }
    for (i = 0; i < m; ++i) {
      int x, y;
      cin >> x >> y;
      sm = 0;
      j = fi(0, x);
      k = fi(j, y);
      copy(a + k, a + l, b);
      copy(a + j, a + k, b + l - k);
      copy(a, a + j, b + l - j);
      copy(b, b + l, a);
    }
    sm = 0;
    j = fi(0, p - 1);
    k = fi(j, q);
    int ct = 0;
    for (i = j; i < k; ++i) {
      if (a[i].first <= r)
        ct += a[i].second;
    }
    cout << ct << endl;
  }
  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
pair<int, int> a[10001], b[10001];
int sm, l;
int fi(int i, int p) {
  for (; sm < p; ++i)
    sm += a[i].second;
  if (sm > p) {
    copy(a + i, a + l, b);
    copy(b, b + l - i, a + i + 1);
    ++l;
    a[i - 1].second -= sm - p;
    a[i] = make_pair(a[i - 1].first + a[i - 1].second, sm - p);
    sm = p;
  }
  return i;
}
int main() {
  int i, j, k;
  int n;
  while (cin >> n) {
    int m, p, q, r;
    cin >> m >> p >> q >> r;
    if (0) {
    } else if (r == n) {
      for (i = 0; i < m; ++i) {
        int x, y;
        cin >> x >> y;
      }
      cout << q - p + 1 << endl;
      continue;
    } else if (r) {
      a[0] = make_pair(1, r);
      a[1] = make_pair(r + 1, n - r);
      l = 2;
    } else {
      for (i = 0; i < m; ++i) {
        int x, y;
        cin >> x >> y;
      }
      cout << 0 << endl;
      continue;
    }
    for (i = 0; i < m; ++i) {
      int x, y;
      cin >> x >> y;
      sm = 0;
      j = fi(0, x);
      k = fi(j, y);
      copy(a + k, a + l, b);
      copy(a + j, a + k, b + l - k);
      copy(a, a + k, b + l - j);
      copy(b, b + l, a);
    }
    sm = 0;
    j = fi(0, p - 1);
    k = fi(j, q);
    int ct = 0;
    for (i = j; i < k; ++i) {
      if (a[i].first <= r)
        ct += a[i].second;
    }
    cout << ct << endl;
  }
  return 0;
}
Problem p00459 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
main() {
  int n, m, p, q, r, x, y;
  vector<int>::iterator v, w, z;
  for (; cin >> n >> m >> p >> q >> r; cout << x << endl) {
    vector<int> t(1), u;

    for (t.push_back(r); m--; u.clear()) {
      cin >> x >> y;
      v = upper_bound(t.begin(), t.end(), x);
      w = upper_bound(t.begin(), t.end(), y);

      if (w - t.begin() + 1 & 1)
        u.push_back(0);
      u.push_back(0);
      for (z = w; z < t.end(); ++z)
        u.push_back(*z - y);

      if (t.end() - v & 1)
        u.push_back(n - y);
      for (z = v; z < w; ++z)
        u.push_back(*z - x + n - y);

      z = t.begin();
      if (w - t.begin() & 1)
        ++z;
      if (!z[1])
        z += 2;
      if (*z + n - x == u.back())
        ++z, u.pop_back();
      for (; z < v; ++z)
        u.push_back(*z + n - x);

      t.swap(u);
    }
    t.insert(upper_bound(t.begin(), t.end(), p - 1), 2, p - 1);
    t.insert(lower_bound(t.begin(), t.end(), q), q);
    t.push_back(n);
    z = upper_bound(t.begin(), t.end(), p - 1);
    if (z - t.begin() & 1)
      --z;
    for (x = 0; *z < q; x += *z++ - m)
      m = *z++;
  }
}

Error: -11

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int n, m, p, q, r, x, y, t;
  vector<int>::iterator itx, ity, it;
  for (; cin >> n >> m >> p >> q >> r; cout << x << endl) {
    vector<int> v1, v2;
    v1.push_back(0);
    v1.push_back(r);

    for (; m--; v2.clear()) {
      cin >> x >> y;
      itx = upper_bound(v1.begin(), v1.end(), x);
      ity = upper_bound(v1.begin(), v1.end(), y);

      if (ity - v1.begin() & 1)
        v2.push_back(0);
      for (it = ity; it != v1.end(); ++it)
        v2.push_back(*it - y);

      if (v1.end() - itx & 1)
        v2.push_back(n - y);
      for (it = itx; it != ity; ++it)
        v2.push_back(*it - x + n - y);

      it = v1.begin();
      if (ity - v1.begin() & 1)
        ++it;
      for (; it != itx; ++it)
        v2.push_back(*it + n - x);

      v1.swap(v2);
    }
    v1.insert(upper_bound(v1.begin(), v1.end(), p - 1), 2, p - 1);
    v1.insert(lower_bound(v1.begin(), v1.end(), q), q);
    v1.push_back(n);
    it = upper_bound(v1.begin(), v1.end(), p - 1);
    if (it - v1.begin() & 1)
      --it;
    for (x = 0; *it < q; ++it) {
      m = *it;
      ++it;
      x += *it - m;
    }
  }
}
Problem p00459 (C++) — buggy submission, verdict: Runtime Error

#include <cstdlib>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  for (int n; cin >> n, n;) {
    int m;
    cin >> m;

    int p, q, r;
    cin >> p >> q >> r;

    vector<pair<int, bool>> cards;
    cards.push_back(make_pair(r, true));
    cards.push_back(make_pair(n - r, false));

    for (int i = 0; i < m; ++i) {
      int x, y;
      cin >> x >> y;

      vector<pair<int, bool>> tmp;
      int j, sum = 0, idxA, idxB, sumA, sumB;
      for (j = 0;; ++j) {
        sum += cards[j].first;
        if (sum >= x) {
          idxA = j;
          sumA = sum;
          sum -= cards[j].first;
          break;
        }
      }

      for (;; ++j) {
        sum += cards[j].first;
        if (sum >= y) {
          idxB = j;
          sumB = sum;
          break;
        }
      }

      if (sumB != y) {
        tmp.push_back(make_pair(sumB - y, cards[idxB].second));
        cards[idxB].first -= sumB - y;

        if (idxA == idxB)
          sumA -= sumB - y;
      }

      for (j = idxB + 1; j < cards.size(); ++j)
        tmp.push_back(cards[j]);

      if (sumA != x) {
        tmp.push_back(make_pair(sumA - x, cards[idxA].second));
        cards[idxA].first -= sumA - x;
      }

      for (j = idxA + 1; j <= idxB; ++j)
        tmp.push_back(cards[j]);

      for (j = 0; j <= idxA; ++j)
        tmp.push_back(cards[j]);

      cards.swap(tmp);
    }

    int ans = 0;
    int i = 0, sum = 0;
    for (; i < cards.size(); ++i) {
      sum += cards[i].first;
      if (sum >= p) {
        if (cards[i].second)
          ans += sum - p + 1;

        break;
      }
    }

    for (++i; i < cards.size(); ++i) {
      sum += cards[i].first;
      if (sum > q) {
        if (cards[i].second)
          ans += cards[i].first - (sum - q);

        break;
      } else {
        if (cards[i].second)
          ans += cards[i].first;
      }
    }

    cout << ans << endl;
  }

  return EXIT_SUCCESS;
}

Error: 0

Fixed submission:

#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  for (int n; cin >> n, n;) {
    int m;
    cin >> m;

    int p, q, r;
    cin >> p >> q >> r;

    vector<int> cards;
    cards.reserve(n);
    for (int i = 1; i <= n; ++i)
      cards.push_back(i);

    for (int i = 0; i < m; ++i) {
      int x, y;
      cin >> x >> y;

      int idx = 0;
      vector<int> tmp(cards);

      for (int j = y; j < n; ++j)
        cards[idx++] = tmp[j];

      for (int j = x; j < y; ++j)
        cards[idx++] = tmp[j];

      for (int j = 0; j < x; ++j)
        cards[idx++] = tmp[j];
    }

    int ans = 0;
    for (int i = p - 1; i < q; ++i)
      if (cards[i] <= r)
        ++ans;

    cout << ans << endl;
  }

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

#include <cstdio>

using namespace std;

const int M = 100000;

int main() {
  for (int n, m, sum; scanf("%d%d%d", &n, &m, &sum), n;) {
    n *= n;
    int dp[50][3001] = {};
    dp[0][0] = 1;
    for (int d = 1; d <= m; d++) {
      for (int i = n; i > 0; i--)
        for (int s = d; s <= sum; s++) {
          dp[i][s] += dp[i - 1][s - d];
          if (dp[i][s] >= M)
            dp[i][s] -= M;
        }
    }
    printf("%d\\n", dp[n][sum]);
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <map>

#define mp make_pair
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

const int M = 100000;

int n, ub;
map<int, int> memo[50][2001];

int dfs(int idx, int lb, int sum) {
  if (idx == n)
    return sum == 0;
  if (sum < 0 || lb > ub)
    return 0;

  if (memo[idx][lb].count(sum) > 0)
    return memo[idx][lb][sum];

  int psum = (lb - 1) * (n - idx) + (n - idx) * (n - idx + 1) / 2;
  if (psum > sum)
    return memo[idx][lb][sum] = 0;

  int cnt = 0;
  for (int i = lb; i <= ub; i++) {
    cnt += dfs(idx + 1, i + 1, sum - i);
    if (cnt >= M)
      cnt -= M;
  }
  return memo[idx][lb][sum] = cnt;
}

int main() {
  for (int sum; scanf("%d%d%d", &n, &ub, &sum), n;) {
    n *= n;
    rep(i, n) rep(lb, ub + 1) memo[i][lb].clear();
    printf("%d\\n", dfs(0, 1, sum));
  }
  return 0;
}
Problem p00460 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int n, m, s;
int dp[55][3003];

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

Error: MLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int n, m, s;
int dp[55][2002][3003];

int solve(int i, int l, int v) {
  if (i == n * n)
    return v == s ? 1 : 0;
  if (dp[i][l][v] >= 0)
    return dp[i][l][v];

  int res = 0;
  for (int j = l; j <= m; j++) {
    if (v + j > s)
      continue;
    res += solve(i + 1, j + 1, v + j);
  }
  return dp[i][l][v] = res % 100000;
}

int main(void) {
  while (cin >> n >> m >> s && n) {
    memset(dp, -1, sizeof(dp));
    cout << solve(0, 1, 0) << endl;
  }
}
Problem p00460 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using namespace std;

#define rep(i, j) REP((i), 0, (j))
#define REP(i, j, k) for (int i = (j); (i) < (k); ++i)
#define BW(a, x, b) ((a) <= (x) && (x) <= (b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int *)a, (int *)(a + LENGTHOF(a)), b)
#define SQ(x) ((x) * (x))
#define Mod(x, mod) (((x)+(mod)%(mod))
#define MP make_pair
#define PB push_back
#define Fi first
#define Se second
#define INF (1 << 29)
#define EPS 1e-10
#define MOD 1000000007

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int N, M, S;
int dp[64][3005];

int main() {
  while (scanf("%d%d%d", &N, &M, &S) && N || M || S) {
    memset(dp, 0, sizeof dp);
    dp[0][0] = 1;
    for (int i = 1; i <= M; i++) {
      for (int j = SQ(N); j >= 0; j--) {
        for (int s = 0; s + i <= S; s++) {
          dp[j + 1][s + i] = (dp[j + 1][s + i] + dp[j][s]) % 100000;
        }
      }
    }
    printf("%d\\n", dp[SQ(N)][S]);
  }
  return 0;
}

Error: TLE

Fixed submission:

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

using namespace std;

#define rep(i, j) REP((i), 0, (j))
#define REP(i, j, k) for (int i = (j); (i) < (k); ++i)
#define BW(a, x, b) ((a) <= (x) && (x) <= (b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int *)a, (int *)(a + LENGTHOF(a)), b)
#define SQ(x) ((x) * (x))
#define Mod(x, mod) (((x)+(mod)%(mod))
#define MP make_pair
#define PB push_back
#define Fi first
#define Se second
#define INF (1 << 29)
#define EPS 1e-10
#define MOD 1000000007

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

const int mod = 100000;

int dp[2][2048][3005];
int N, M, S;

int main() {
  while (scanf("%d%d%d", &N, &M, &S) && N || M || S) {
    memset(dp, 0, sizeof dp);
    dp[0][0][0] = 1;
    int cur = 0, tar = 1;
    for (int i = 0; i < N * N; i++) {
      cur = i & 1, tar = cur ^ 1;
      memset(dp[tar], 0, sizeof dp[tar]);
      for (int j = 0; j <= M; j++) {
        for (int k = 0; k <= S; k++) {
          for (int l = j + 1; l <= M; l++) {
            if (k + l > S)
              continue;
            dp[tar][l][k + l] = (dp[tar][l][k + l] + dp[cur][j][k]) % mod;
          }
        }
      }
    }
    int res = 0;
    for (int i = 0; i <= M; i++)
      res = (res + dp[tar][i][S]) % mod;
    printf("%d\\n", res);
  }
  return 0;
}
Problem p00460 (C++) — buggy submission, verdict: Memory Limit Exceeded

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

Error: MLE

Fixed submission:

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