prithivMLmods/Coder-Stat huggingface dataset:
Problem p00089 (C++)

Buggy submission (status: Runtime Error):
#include <math.h>
#include <stack>
#include <stdio.h>

using namespace std;

int main() {

  int dp[100][1000], row = 0, tmp, index, width[100], max_width = 0,
                     max_width_row;
  char buf[55];

  while (scanf("%s", buf) != EOF) {
    index = tmp = 0;
    for (int i = 0; buf[i] != '\0'; i++) {
      if (buf[i] >= '0' && buf[i] <= '9') {
        tmp = tmp * 10 + (buf[i] - '0');
        if (buf[i + 1] == '\0') {
          dp[row][index++] = tmp;
        }
      } else {
        dp[row][index++] = tmp;
        tmp = 0;
      }
    }
    if (max_width < index) {
      max_width = index;
      max_width_row = row;
    }

    width[row] = index;
    row++;
  }

  for (int i = 1; i <= max_width_row; i++) {
    for (int k = 0; k < width[i]; k++) {
      if (k == 0) {
        dp[i][0] += dp[i - 1][0];
      } else if (k == width[i] - 1) {
        dp[i][k] += dp[i - 1][width[i - 1] - 1];
      } else {
        dp[i][k] += max(dp[i - 1][k - 1], dp[i - 1][k]);
      }
    }
  }

  for (int i = max_width_row + 1; i < row; i++) {
    for (int k = 0; k < width[i]; k++) {
      dp[i][k] += max(dp[i - 1][k], dp[i - 1][k + 1]);
    }
  }

  printf("%d\n", dp[row - 1][0]);

  return 0;
}

Fixed submission:
#include <math.h>
#include <stack>
#include <stdio.h>

using namespace std;

int main() {

  int dp[100][200], row = 0, tmp, index, width[100], max_width = 0,
                    max_width_row;
  char buf[200];

  while (scanf("%s", buf) != EOF) {
    index = tmp = 0;
    for (int i = 0; buf[i] != '\0'; i++) {
      if (buf[i] >= '0' && buf[i] <= '9') {
        tmp = tmp * 10 + (buf[i] - '0');
        if (buf[i + 1] == '\0') {
          dp[row][index++] = tmp;
        }
      } else {
        dp[row][index++] = tmp;
        tmp = 0;
      }
    }
    if (max_width < index) {
      max_width = index;
      max_width_row = row;
    }

    width[row] = index;
    row++;
  }

  for (int i = 1; i <= max_width_row; i++) {
    for (int k = 0; k < width[i]; k++) {
      if (k == 0) {
        dp[i][0] += dp[i - 1][0];
      } else if (k == width[i] - 1) {
        dp[i][k] += dp[i - 1][width[i - 1] - 1];
      } else {
        dp[i][k] += max(dp[i - 1][k - 1], dp[i - 1][k]);
      }
    }
  }

  for (int i = max_width_row + 1; i < row; i++) {
    for (int k = 0; k < width[i]; k++) {
      dp[i][k] += max(dp[i - 1][k], dp[i - 1][k + 1]);
    }
  }

  printf("%d\n", dp[row - 1][0]);

  return 0;
}
Problem p00089 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <string>
using namespace std;

int n[99][50], m[99][50];
string s[99];

int main() {
  int l = 0;
  while (getline(cin, s[l]))
    l++;
  for (int i = 0; i < l; i++) {
    int pos = 0, cur = 0;
    while (pos < s[i].size()) {
      if (isdigit(s[i][pos]))
        n[i][cur] = n[i][cur] * 10 + s[i][pos] - '0';
      else
        cur++;
      pos++;
    }
  }
  m[0][0] = n[0][0];
  for (int i = 1; i <= l / 2; i++) {
    m[i][0] = m[i - 1][0] + n[i][0];
    m[i][i] = m[i - 1][i - 1] + n[i][i];
    for (int j = 1; j < i; j++)
      m[i][j] = max(m[i - 1][j - 1], m[i - 1][j]) + n[i][j];
  }
  for (int i = l / 2 + 1; i < l; i++) {
    for (int j = 0; j < l - i; j++) {
      m[i][j] = max(m[i - 1][j], m[i - 1][j + 1]) + n[i][j];
    }
  }
  cout << m[l - 1][0] << endl;
}

Fixed submission:
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <string>
using namespace std;

int n[99][50], m[99][50];
string s[100];

int main() {
  int l = 0;
  while (getline(cin, s[l]))
    l++;
  for (int i = 0; i < l; i++) {
    int pos = 0, cur = 0;
    while (pos < s[i].size()) {
      if (isdigit(s[i][pos]))
        n[i][cur] = n[i][cur] * 10 + s[i][pos] - '0';
      else
        cur++;
      pos++;
    }
  }
  m[0][0] = n[0][0];
  for (int i = 1; i <= l / 2; i++) {
    m[i][0] = m[i - 1][0] + n[i][0];
    m[i][i] = m[i - 1][i - 1] + n[i][i];
    for (int j = 1; j < i; j++)
      m[i][j] = max(m[i - 1][j - 1], m[i - 1][j]) + n[i][j];
  }
  for (int i = l / 2 + 1; i < l; i++) {
    for (int j = 0; j < l - i; j++) {
      m[i][j] = max(m[i - 1][j], m[i - 1][j + 1]) + n[i][j];
    }
  }
  cout << m[l - 1][0] << endl;
}
Problem p00092 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = n - 1; i >= 0; i--)

#define PB push_back
#define INF INT_MAX / 3
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset(a, 0, sizeof(a))

typedef long long int ll;

using namespace std;

int main() {
  while (true) {
    int n;
    cin >> n;
    vector<vector<char>> map(n, vector<char>(n, '.'));
    REP(i, n) {
      REP(j, n) { cin >> map[i][j]; }
    }
    if (n == 0)
      break;
    bool flg = true;
    int high, low, middle;
    high = n + 1;
    low = 0;
    middle = (high + low) / 2;

    while (high - low > 1) {
      REP(j, n - middle + 1) {
        REP(k, n - middle + 1) {
          flg = true;
          REP(l, middle) {
            REP(m, middle) {
              if (map[j + l][k + m] == '*') {
                flg = false;
                break;
              }
            }
            if (!flg)
              break;
          }
          if (flg) {
            break;
          }
        }
        if (flg)
          break;
      }
      if (flg) {
        low = middle;
      } else {
        high = middle;
      }
      middle = (high + low) / 2;
    }
    cout << middle << endl;
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = n - 1; i >= 0; i--)

#define PB push_back
#define INF INT_MAX / 3
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset(a, 0, sizeof(a))

typedef long long int ll;

using namespace std;

int main() {
  while (true) {
    int n;
    cin >> n;
    vector<vector<char>> map(n, vector<char>(n, '.'));
    REP(i, n) {
      REP(j, n) { cin >> map[i][j]; }
    }
    if (n == 0)
      break;
    bool flg = true;
    int high, low, middle;
    high = n + 1;
    low = 0;
    middle = (high + low) / 2;

    while (high - low > 1) {
      REP(j, n - middle + 1) {
        REP(k, n - middle + 1) {
          flg = true;
          REP(l, middle) {
            REP(m, middle) {
              if (map[j + l][k + m] == '*') {
                flg = false;
                k = k + m;
                if (k >= n - middle + 1)
                  break;
                break;
              }
            }
            if (!flg)
              break;
          }
          if (flg) {
            break;
          }
        }
        if (flg)
          break;
      }
      if (flg) {
        low = middle;
      } else {
        high = middle;
      }
      middle = (high + low) / 2;
    }
    cout << middle << endl;
  }
  return 0;
}
Problem p00092 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cmath>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int n;

  while (cin >> n) {
    if (n == 0) {
      break;
    }
    vector<vector<char>> d(n, vector<char>(n));
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        cin >> d[i][j];
      }
    }
    vector<vector<int>> dd(n, vector<int>(n));
    int c = 0;
    for (int i = 0; i < n; i++) {
      int cc = 0;
      for (int j = n - 1; j >= 0; j--) {
        if (d[i][j] == '.') {
          cc++;
        } else {
          cc = 0;
        }
        dd[i][j] = cc;
      }
    }
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (dd[i][j] > c) {
          int ccc = dd[i][j];
          for (int k = 0; i + k < n; k++) {
            if (dd[i + k][j] == 0) {
              break;
            }
            ccc = min(ccc, dd[i + k][j]);
            if (ccc <= k + 1) {
              c = max(c, ccc);
            }
          }
        }
      }
    }
    cout << c << endl;
  }

  return 0;
}

Fixed submission:
#include <cmath>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int n;

  while (cin >> n) {
    if (n == 0) {
      break;
    }
    vector<vector<char>> d(n, vector<char>(n));
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        cin >> d[i][j];
      }
    }
    vector<vector<int>> dd(n, vector<int>(n));
    int c = 0;
    for (int i = 0; i < n; i++) {
      int cc = 0;
      for (int j = n - 1; j >= 0; j--) {
        if (d[i][j] == '.') {
          cc++;
        } else {
          cc = 0;
        }
        dd[i][j] = cc;
      }
    }
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (dd[i][j] > c) {
          int ccc = dd[i][j];
          for (int k = 0; i + k < n; k++) {
            if (dd[i + k][j] <= c) {
              break;
            }
            ccc = min(ccc, dd[i + k][j]);
            if (ccc <= k + 1) {
              c = max(c, ccc);
            }
          }
        }
      }
    }
    cout << c << endl;
  }

  return 0;
}
Problem p00092 (C++)

Buggy submission (status: Time 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 long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 100000;
int cnt[1000][1000];
int main() {
  int n;
  char fld[1000][1000];
  while (scanf("%d", &n) && n) {
    memset(cnt, 0, sizeof(cnt));
    REP(i, n) {
      scanf("%s", fld[i]);
      REP(j, n) if (fld[i][j] == '*') cnt[i][j]++;
    }
    // REP(i,n){REP(j,n)cout<<cnt[j][i];cout<<endl;}
    REP(i, n) REP(j, n) {
      if (i != 0)
        cnt[j][i] += cnt[j][i - 1];
      if (j != 0)
        cnt[j][i] += cnt[j - 1][i];
      if (i != 0 && j != 0)
        cnt[j][i] -= cnt[j - 1][i - 1];
    }
    // REP(i,n){REP(j,n)cout<<cnt[j][i]<<" ";cout<<endl;}
    int ans = 0;
    REP(x, n) REP(y, n) {
      REP(d, min(n - x, n - y)) {
        int nx = x + d, ny = y + d;
        int c = cnt[ny][nx];
        if (x != 0)
          c -= cnt[ny][x - 1];
        if (y != 0)
          c -= cnt[y - 1][nx];
        if (x != 0 && y != 0)
          c += cnt[y - 1][x - 1];
        if (c == 0 && ans < d + 1) {
          // cout<<x<<" "<<y<<" "<<d+1<<endl;
          ans = d + 1;
        }
      }
    }
    printf("%d\n", ans);
  }
}

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 long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 100000;
int cnt[1000][1000];
int main() {
  int n;
  char fld[1000][1000];
  while (scanf("%d", &n) && n) {
    memset(cnt, 0, sizeof(cnt));
    REP(i, n) {
      scanf("%s", fld[i]);
      REP(j, n) if (fld[i][j] == '*') cnt[i][j]++;
    }
    // REP(i,n){REP(j,n)cout<<cnt[j][i];cout<<endl;}
    REP(i, n) REP(j, n) {
      if (i != 0)
        cnt[j][i] += cnt[j][i - 1];
      if (j != 0)
        cnt[j][i] += cnt[j - 1][i];
      if (i != 0 && j != 0)
        cnt[j][i] -= cnt[j - 1][i - 1];
    }
    // REP(i,n){REP(j,n)cout<<cnt[j][i]<<" ";cout<<endl;}
    int ans = 0;
    REP(x, n) REP(y, n) {
      for (int d = ans; d < min(n - x, n - y); d++) {
        int nx = x + d, ny = y + d;
        int c = cnt[ny][nx];
        if (x != 0)
          c -= cnt[ny][x - 1];
        if (y != 0)
          c -= cnt[y - 1][nx];
        if (x != 0 && y != 0)
          c += cnt[y - 1][x - 1];
        if (c == 0 && ans < d + 1) {
          // cout<<x<<" "<<y<<" "<<d+1<<endl;
          ans = d + 1;
        }
      }
    }
    printf("%d\n", ans);
  }
}
Problem p00092 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int dp[1001][1001];
int latte(int i, int j, int k) {
  return dp[i + k][j + k] - dp[i + k][j - 1] - dp[i - 1][j + k] +
         dp[i - 1][j - 1];
}
int main() {
  int n;
  while (cin >> n, n) {
    fill(dp[0], dp[0] + 1001 * 1001, 0);
    for (int i = 0; i < n; i++) {
      string str;
      cin >> str;
      for (int j = 0; j < n; j++) {
        dp[i + 1][j + 1] = dp[i][j + 1] + dp[i + 1][j] - dp[i][j];
        if (str[j] == '*')
          dp[i + 1][j + 1]++;
      }
    }
    int Max = 0;
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
        if (latte(i, j, 0))
          continue;
        int lb = 0, ub = max(n - i, n - j) + 1;
        while (ub - lb > 1) {
          int k = (ub + lb) / 2;
          // if(i+k>n||j+k>n)ub=k;
          if (latte(i, j, k))
            ub = k;
          else
            lb = k;
        }
        Max = max(Max, lb + 1);
      }
    }
    cout << Max << endl;
  }
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int dp[1001][1001];
int latte(int i, int j, int k) {
  return dp[i + k][j + k] - dp[i + k][j - 1] - dp[i - 1][j + k] +
         dp[i - 1][j - 1];
}
int main() {
  int n;
  while (cin >> n, n) {
    fill(dp[0], dp[0] + 1001 * 1001, 0);
    for (int i = 0; i < n; i++) {
      string str;
      cin >> str;
      for (int j = 0; j < n; j++) {
        dp[i + 1][j + 1] = dp[i][j + 1] + dp[i + 1][j] - dp[i][j];
        if (str[j] == '*')
          dp[i + 1][j + 1]++;
      }
    }
    int Max = 0;
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
        if (latte(i, j, 0))
          continue;
        int lb = 0, ub = min(n - i, n - j) + 1;
        while (ub - lb > 1) {
          int k = (ub + lb) / 2;
          // if(i+k>n||j+k>n)ub=k;
          if (latte(i, j, k))
            ub = k;
          else
            lb = k;
        }
        Max = max(Max, lb + 1);
      }
    }
    cout << Max << endl;
  }
}
Problem p00092 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
using namespace std;
#define MAX 504

int hseq[MAX][MAX];
int vseq[MAX][MAX];
int sq[MAX][MAX];
char f[MAX][MAX];

int main() {
  while (true) {
    int n;
    scanf("%d", &n);
    if (n == 0)
      break;
    int ans = 0;
    for (int y = 1; y <= n; ++y) {
      scanf("%s", &f[y][1]);
      for (int x = 1; x <= n; ++x) {
        hseq[y][x] = f[y][x] == '.' ? hseq[y][x - 1] + 1 : 0;
        vseq[y][x] = f[y][x] == '.' ? vseq[y - 1][x] + 1 : 0;
        sq[y][x] =
            f[y][x] == '.'
                ? min(sq[y - 1][x - 1], min(hseq[y][x - 1], vseq[y - 1][x])) + 1
                : 0;
        ans = max(ans, sq[y][x]);
      }
    }
    /*
    for(int y=1; y<=n; ++y) {
      for(int x=1; x<=n; ++x) {
        printf(" %2d", sq[y][x]);
      }
      printf("\n");
    }
    */
    printf("%d\n", ans);
  }
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cstdio>
using namespace std;
#define MAX 1004

int hseq[MAX][MAX];
int vseq[MAX][MAX];
int sq[MAX][MAX];
char f[MAX][MAX];

int main() {
  while (true) {
    int n;
    scanf("%d", &n);
    if (n == 0)
      break;
    int ans = 0;
    for (int y = 1; y <= n; ++y) {
      scanf("%s", &f[y][1]);
      for (int x = 1; x <= n; ++x) {
        hseq[y][x] = f[y][x] == '.' ? hseq[y][x - 1] + 1 : 0;
        vseq[y][x] = f[y][x] == '.' ? vseq[y - 1][x] + 1 : 0;
        sq[y][x] =
            f[y][x] == '.'
                ? min(sq[y - 1][x - 1], min(hseq[y][x - 1], vseq[y - 1][x])) + 1
                : 0;
        ans = max(ans, sq[y][x]);
      }
    }
    /*
    for(int y=1; y<=n; ++y) {
      for(int x=1; x<=n; ++x) {
        printf(" %2d", sq[y][x]);
      }
      printf("\n");
    }
    */
    printf("%d\n", ans);
  }
  return 0;
}
Problem p00092 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <stdio.h>
using namespace std;
int main() {
  int n, ans = 0;
  int dp[110][110];
  char field;
  while (scanf("%d", &n), n) {
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++) {
        scanf(" %c", &field);
        dp[j + 1][i + 1] = 0;
        if (field == '*')
          dp[j + 1][i + 1] = -1;
      }
    for (int i = 1; i < n + 1; i++) {
      for (int j = 1; j < n + 1; j++) {
        if (dp[j][i] == -1)
          ;
        else if (j == 1 || i == 1)
          dp[j][i] = 1;
        else
          dp[j][i] = max(
              1, min(dp[j - 1][i - 1], min(dp[j - 1][i], dp[j][i - 1])) + 1);
        ans = max(ans, dp[j][i]);
      }
    }
    /*for(int i = 1; i < n + 1; i++)
    {
        for(int j = 1; j < n + 1; j++)
        {
            printf("%2d",dp[j][i]);
        }
        printf("\n");
    }*/
    printf("%d\n", ans);
    ans = 0;
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <stdio.h>
using namespace std;
int main() {
  int n, ans = 0;
  int dp[1100][1100];
  char field;
  while (scanf("%d", &n), n) {
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++) {
        scanf(" %c", &field);
        dp[j + 1][i + 1] = 0;
        if (field == '*')
          dp[j + 1][i + 1] = -1;
      }
    for (int i = 1; i < n + 1; i++) {
      for (int j = 1; j < n + 1; j++) {
        if (dp[j][i] == -1)
          ;
        else if (j == 1 || i == 1)
          dp[j][i] = 1;
        else
          dp[j][i] = max(
              1, min(dp[j - 1][i - 1], min(dp[j - 1][i], dp[j][i - 1])) + 1);
        ans = max(ans, dp[j][i]);
      }
    }
    /*for(int i = 1; i < n + 1; i++)
    {
        for(int j = 1; j < n + 1; j++)
        {
            printf("%2d",dp[j][i]);
        }
        printf("\n");
    }*/
    printf("%d\n", ans);
    ans = 0;
  }
  return 0;
}
Problem p00092 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cstdio>
using namespace std;

int n;
int ans;
int dp[10000][10000];

int main() {
  while (1) {
    scanf("%d", &n);
    if (n == 0)
      return 0;

    ans = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        char c;
        scanf("%c ", &c);
        if (c == '.') {
          dp[i][j] = 1;
          if (i > 0 && j > 0) {
            int t = min(dp[i - 1][j], dp[i][j - 1]);
            dp[i][j] = max(dp[i][j], min(t, dp[i - 1][j - 1]) + 1);
          }
        } else
          dp[i][j] = 0;

        ans = max(ans, dp[i][j]);
      }
    }

    printf("%d\n", ans);
  }
}

Fixed submission:
#include <algorithm>
#include <cstdio>
using namespace std;

int n;
int ans;
int dp[10000][10000];

int main() {
  while (1) {
    scanf("%d", &n);
    if (n == 0)
      return 0;

    ans = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        char c;
        scanf(" %c", &c);
        if (c == '.') {
          dp[i][j] = 1;
          if (i > 0 && j > 0) {
            int t = min(dp[i - 1][j], dp[i][j - 1]);
            dp[i][j] = max(dp[i][j], min(t, dp[i - 1][j - 1]) + 1);
          }
        } else
          dp[i][j] = 0;

        ans = max(ans, dp[i][j]);
      }
    }

    printf("%d\n", ans);
  }
}
Problem p00092 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>

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

using namespace std;

int w[1005][1005];
int main() {
  string s[1005];
  int n;
  while (cin >> n && n) {
    memset(w, 0, sizeof(w));
    rep(i, n) { cin >> s[i]; }

    rep(i, n) {
      rep(j, n) {
        if (s[i][j] == '*')
          w[i][j] = 0;
        else
          w[i][j] = 1;
      }
    }

    int ans = 0;
    rep(i, n) {
      rep(j, n) {
        if (s[i][j] == '*') {
          w[i][j] = 0;
        } else {
          w[i][j] = min(w[i - 1][j - 1], min(w[i - 1][j], w[i][j - 1])) + 1;
          ans = max(ans, w[i][j]);
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>

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

using namespace std;

int w[1005][1005];
int main() {
  string s[1005];
  int n;
  while (cin >> n && n) {
    memset(w, 0, sizeof(w));
    rep(i, n) { cin >> s[i]; }

    rep(i, n) {
      rep(j, n) {
        if (s[i][j] == '*')
          w[i][j] = 0;
        else
          w[i][j] = 1;
      }
    }

    int ans = 0;
    REP(i, 1, n) {
      REP(j, 1, n) {
        if (s[i][j] == '*') {
          w[i][j] = 0;
        } else {
          w[i][j] = min(w[i - 1][j - 1], min(w[i - 1][j], w[i][j - 1])) + 1;
          ans = max(ans, w[i][j]);
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p00092 (C++)

Buggy submission (status: Time Limit Exceeded):
// 23
#include <algorithm>
#include <cstring>
#include <iostream>

using namespace std;

int main() {
  for (int n; cin >> n, n;) {
    int c[1000] = {};
    int ans = 0;
    for (int i = 0; i < n; i++) {
      char l[1001];
      cin >> l;
      int cl[1000];
      for (int j = 0; j < n; j++) {
        cl[j] = (l[j] == '*') ? 0 : c[j] + 1;
      }
      for (int j = 1; j <= n; j++) {
        int ms = 0, cs = 0;
        for (int k = 0; k < n; k++) {
          if (cl[k] >= j) {
            cs++;
            ms = max(ms, cs);
          } else {
            cs = 0;
          }
        }
        if (ms < j)
          break;
        ans = max(ans, j);
      }
      memcpy(c, cl, sizeof(c));
    }
    cout << ans << endl;
  }
  return 0;
}

Fixed submission:
// 23
#include <algorithm>
#include <cstring>
#include <iostream>

using namespace std;

int main() {
  for (int n; cin >> n, n;) {
    int c[1000] = {};
    int ans = 0;
    for (int i = 0; i < n; i++) {
      char l[1001];
      cin >> l;
      int cl[1000];
      for (int j = 0; j < n; j++) {
        cl[j] = (l[j] == '*') ? 0 : c[j] + 1;
      }
      for (int j = ans + 1; j <= n; j++) {
        int ms = 0, cs = 0;
        for (int k = 0; k < n; k++) {
          if (cl[k] >= j) {
            cs++;
            ms = max(ms, cs);
          } else {
            cs = 0;
          }
        }
        if (ms < j)
          break;
        ans = max(ans, j);
      }
      memcpy(c, cl, sizeof(c));
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p00092 (C++)

Buggy submission (status: Time Limit Exceeded):
// Name: Square Searching
// Level: 2
// Category: 動的計画法,DP,累積和
// Note:

/*
 * 座標(0,0)と(r,c)をそれぞれ左上，右下に持つ矩形を考えて，その中の*の数を記憶しておく．
 * これを使うと任意の矩形内の*の数がO(1)で求められる．
 * 正方形の左上は任意に決められるのでN^2通り存在し，それに対応する右下の決め方は高々N通りである．
 * (正方形であることに注意)．
 * したがって，ナイーブに探索するとO(N^3)個の正方形について内部の*の数を数え，0個のもののサイズを覚えればよい．
 */
#include <algorithm>
#include <iostream>
#include <string>

using namespace std;

int dp[1000][1000];
int N;

inline int get(int r, int c) {
  if (r < 0 || r >= N || c < 0 || c >= N)
    return 0;
  return dp[r][c];
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  while (cin >> N) {
    if (N == 0)
      break;
    for (int i = 0; i < N; ++i) {
      string line;
      cin >> line;
      for (int c = 0; c < N; ++c) {
        dp[i][c] = get(i - 1, c) + get(i, c - 1) - get(i - 1, c - 1);
        if (line[c] == '*')
          dp[i][c]++;
      }
    }
    int ans = 0;
    for (int r = 0; r < N; ++r) {
      for (int c = 0; c < N; ++c) {
        for (int size = 1; size <= N; ++size) {
          const int er = r + size - 1;
          const int ec = c + size - 1;
          if (er >= N || ec >= N)
            break;
          const int marks =
              get(er, ec) - get(er, c - 1) - get(r - 1, ec) + get(r - 1, c - 1);
          if (marks == 0) {
            ans = max(ans, size);
          }
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Fixed submission:
// Name: Square Searching
// Level: 2
// Category: 動的計画法,DP,累積和
// Note:

/*
 * 座標(0,0)と(r,c)をそれぞれ左上，右下に持つ矩形を考えて，その中の*の数を記憶しておく．
 * これを使うと任意の矩形内の*の数がO(1)で求められる．
 * 正方形の左上は任意に決められるのでN^2通り存在し，それに対応する右下の決め方は高々N通りである．
 * (正方形であることに注意)．
 * したがって，ナイーブに探索するとO(N^3)個の正方形について内部の*の数を数え，0個のもののサイズを覚えればよい．
 */
#include <algorithm>
#include <iostream>
#include <string>

using namespace std;

int dp[1000][1000];
int N;

inline int get(int r, int c) {
  if (r < 0 || r >= N || c < 0 || c >= N)
    return 0;
  return dp[r][c];
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  while (cin >> N) {
    if (N == 0)
      break;
    for (int i = 0; i < N; ++i) {
      string line;
      cin >> line;
      for (int c = 0; c < N; ++c) {
        dp[i][c] = get(i - 1, c) + get(i, c - 1) - get(i - 1, c - 1);
        if (line[c] == '*')
          dp[i][c]++;
      }
    }
    int ans = 0;
    for (int r = 0; r < N; ++r) {
      for (int c = 0; c < N; ++c) {
        for (int size = ans + 1; size <= N; ++size) {
          const int er = r + size - 1;
          const int ec = c + size - 1;
          if (er >= N || ec >= N)
            break;
          const int marks =
              get(er, ec) - get(er, c - 1) - get(r - 1, ec) + get(r - 1, c - 1);
          if (marks == 0) {
            ans = max(ans, size);
          }
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p00092 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <iostream>

#define INF 2100000000

using namespace std;

int minix(int a, int b, int c) {
  if (b >= a && c >= a) {
    return a;
  }
  if (a >= b && c >= b) {
    return b;
  }
  if (b >= c && a >= c) {
    return c;
  }
}

int main() {
  int n;
  int masu[102][102];
  int ura[102][102];
  char str[1002];
  while (1) {
    scanf("%d", &n);
    if (n == 0) {
      break;
    }
    for (int i = 1; i <= n; i++) {
      scanf("%s", str);
      for (int j = 1; j <= n; j++) {
        if (str[j - 1] == '.') {
          ura[i][j] = 0;
        } else {
          ura[i][j] = 1;
        }
      }
    }
    for (int i = 0; i <= n; i++) {
      masu[i][0] = masu[0][i] = 0;
    }
    int maxi = 0;
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
        if (ura[i][j] == 0) {
          masu[i][j] =
              minix(masu[i - 1][j], masu[i][j - 1], masu[i - 1][j - 1]) + 1;
          maxi = max(masu[i][j], maxi);
        } else {
          masu[i][j] = 0;
        }
      }
    }

    printf("%d\n", maxi);
  }
}

Fixed submission:
#include <cstdio>
#include <iostream>

#define INF 2100000000

using namespace std;

int minix(int a, int b, int c) {
  if (b >= a && c >= a) {
    return a;
  }
  if (a >= b && c >= b) {
    return b;
  }
  if (b >= c && a >= c) {
    return c;
  }
}

int main() {
  int n;
  int masu[1002][1002];
  int ura[1002][1002];
  char str[1002];
  while (1) {
    scanf("%d", &n);
    if (n == 0) {
      break;
    }
    for (int i = 1; i <= n; i++) {
      scanf("%s", str);
      for (int j = 1; j <= n; j++) {
        if (str[j - 1] == '.') {
          ura[i][j] = 0;
        } else {
          ura[i][j] = 1;
        }
      }
    }
    for (int i = 0; i <= n; i++) {
      masu[i][0] = masu[0][i] = 0;
    }
    int maxi = 0;
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
        if (ura[i][j] == 0) {
          masu[i][j] =
              minix(masu[i - 1][j], masu[i][j - 1], masu[i - 1][j - 1]) + 1;
          maxi = max(masu[i][j], maxi);
        } else {
          masu[i][j] = 0;
        }
      }
    }

    printf("%d\n", maxi);
  }
}
Problem p00092 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <string>
using namespace std;

int isSquare(string map[], int x, int y, int size) {
  for (int i = 0; i < size; i++) {
    for (int j = 0; j < size; j++) {
      int nx = x + j, ny = y + i;
      if (nx >= map[0].length() || ny >= map[0].length())
        return 0;
      if (map[ny][nx] == '*')
        return 0;
    }
  }
  return 1;
}

int main() {
  int n;

  while (1) {
    cin >> n;
    if (n == 0)
      break;
    string map[10];
    getchar();
    for (int i = 0; i < n; i++) {
      getline(cin, map[i]);
    }
    int max = 0;

    for (int s = 1; s <= n; s++) {
      bool flag = false;
      for (int i = 0; !flag && i <= n - s; i++) {
        for (int j = 0; !flag && j <= n - s; j++) {
          if (isSquare(map, j, i, s)) {
            max = s;
            flag = true;
          }
        }
      }
      if (!flag)
        break;
    }
    cout << max << endl;
  }
  return 0;
}

Fixed submission:
#include <iostream>
#include <string>
using namespace std;

int isSquare(string map[], int x, int y, int size) {
  for (int i = 0; i < size; i++) {
    for (int j = 0; j < size; j++) {
      int nx = x + j, ny = y + i;
      if (nx >= map[0].length() || ny >= map[0].length())
        return 0;
      if (map[ny][nx] == '*')
        return 0;
    }
  }
  return 1;
}

int main() {
  int n;

  while (1) {
    cin >> n;
    if (n == 0)
      break;
    string map[n];
    getchar();
    for (int i = 0; i < n; i++) {
      getline(cin, map[i]);
    }
    int max = 0;

    for (int s = 1; s <= n; s++) {
      bool flag = false;
      for (int i = 0; !flag && i <= n - s; i++) {
        for (int j = 0; !flag && j <= n - s; j++) {
          if (isSquare(map, j, i, s)) {
            max = s;
            flag = true;
          }
        }
      }
      if (!flag)
        break;
    }
    cout << max << endl;
  }
  return 0;
}
Problem p00092 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cstdio>
#include <iostream>

using namespace std;
int main() {
  int n;
  for (; cin >> n, n;) {
    string map[n];
    int sum[n][n];
    for (int i = 0; i < n; i++) {
      cin >> map[i];
      for (int j = 0; j < n; j++) {
        int tmp = 0;
        if (j > 0)
          tmp += sum[i][j - 1];
        if (i > 0)
          tmp += sum[i - 1][j];
        if (j > 0 && i > 0)
          tmp -= sum[i - 1][j - 1];
        if (map[i][j] == '.')
          tmp++;
        sum[i][j] = tmp;
      }
    }
    /*      cout<<endl;
    for(int i=0;i<n;i++,cout<<endl)
      for(int j=0;j<n;j++)
      printf("%3d ",sum[i][j]);*/
    int ans = 0;
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++)
        for (int x = min(i, j); x >= 0; x--) {
          int tmp = sum[i][j];
          if (i - x > 0)
            tmp -= sum[i - x - 1][j];
          if (j - x > 0)
            tmp -= sum[i][j - x - 1];
          if (i - x > 0 && j - x > 0)
            tmp += sum[i - x - 1][j - x - 1];
          if ((x + 1) * (x + 1) == tmp)
            ans = max(x + 1, ans);
        }
    cout << ans << endl;
  }
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <iostream>

using namespace std;
int main() {
  int n;
  for (; cin >> n, n;) {
    string map[n];
    int sum[n][n];
    for (int i = 0; i < n; i++) {
      cin >> map[i];
      for (int j = 0; j < n; j++) {
        int tmp = 0;
        if (j > 0)
          tmp += sum[i][j - 1];
        if (i > 0)
          tmp += sum[i - 1][j];
        if (j > 0 && i > 0)
          tmp -= sum[i - 1][j - 1];
        if (map[i][j] == '.')
          tmp++;
        sum[i][j] = tmp;
      }
    }
    /*      cout<<endl;
    for(int i=0;i<n;i++,cout<<endl)
      for(int j=0;j<n;j++)
      printf("%3d ",sum[i][j]);*/
    int ans = 0;
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++)
        for (int x = min(i, j); x >= ans; x--) {
          int tmp = sum[i][j];
          if (i - x > 0)
            tmp -= sum[i - x - 1][j];
          if (j - x > 0)
            tmp -= sum[i][j - x - 1];
          if (i - x > 0 && j - x > 0)
            tmp += sum[i - x - 1][j - x - 1];
          if ((x + 1) * (x + 1) == tmp)
            ans = max(x + 1, ans);
        }
    cout << ans << endl;
  }
}
Problem p00092 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;

int dp[1002][1002];

int main() {
  int n;
  while (scanf("%d", &n), n) {
    int ret = 0;
    char line[101];
    for (int i = 1; i <= n; ++i) {
      scanf("%s", line);
      for (int j = 0; j < n; ++j) {
        if (line[j] == '.') {
          dp[i][j] = min(dp[i - 1][j - 1], min(dp[i - 1][j], dp[i][j - 1])) + 1;
          ret = max(ret, dp[i][j]);
        } else {
          dp[i][j] = 0;
        }
      }
    }
    printf("%d\n", ret);
  }
  return 0;
}

Fixed submission:
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;

int dp[1002][1002];

int main() {
  int n;
  while (scanf("%d", &n), n) {
    int ret = 0;
    char line[1001];
    for (int i = 1; i <= n; ++i) {
      scanf("%s", line);
      for (int j = 0; j < n; ++j) {
        if (line[j] == '.') {
          dp[i][j] = min(dp[i - 1][j - 1], min(dp[i - 1][j], dp[i][j - 1])) + 1;
          ret = max(ret, dp[i][j]);
        } else {
          dp[i][j] = 0;
        }
      }
    }
    printf("%d\n", ret);
  }
  return 0;
}
Problem p00093 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;
int x[10000], y[10000][10000], a, b, cnt2;

void uruu(int s) {
  for (int i = 0; i < s; i++) {
    if ((i % 4 == 0 && i % 100 != 0) || i % 400 == 0) {
      x[i] = 1;
    }
  }
}

void hantei(int start, int end) {
  int cnt = 0;
  for (int i = start; i <= end; i++) {
    if (x[i]) {
      cout << i << endl;
      cnt++;
    }
  }
  if (!cnt) {
    cout << "NA" << endl;
  }
}

int main() {
  uruu(10000);
  while (true) {
    cin >> a >> b;
    if (cnt2) {
      cout << endl;
    }
    cnt2++;
    hantei(a, b);
  }
}

Fixed submission:
#include <iostream>
using namespace std;
int x[10000], y[10000][10000], a, b, cnt2;

void uruu(int s) {
  for (int i = 0; i < s; i++) {
    if ((i % 4 == 0 && i % 100 != 0) || i % 400 == 0) {
      x[i] = 1;
    }
  }
}

void hantei(int start, int end) {
  int cnt = 0;
  for (int i = start; i <= end; i++) {
    if (x[i]) {
      cout << i << endl;
      cnt++;
    }
  }
  if (!cnt) {
    cout << "NA" << endl;
  }
}

int main() {
  uruu(10000);
  while (true) {
    cin >> a >> b;
    if (!a) {
      break;
    }
    if (cnt2) {
      cout << endl;
    }
    cnt2++;
    hantei(a, b);
  }
}
Problem p00094 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cstdio>
int main() {
  int a, b;
  for (; scanf("%d%d", &a, &b);)
    printf("%f", (double)a * b / 3.305785);
}

Fixed submission:
#include <cstdio>
int main() {
  int a, b;
  for (; ~scanf("%d%d", &a, &b);)
    printf("%f", (double)a * b / 3.305785);
}
Problem p00095 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <stdio.h>

int main() {

  int x, y, n;
  int X = 0, Y = 0;

  scanf("%d", &n);

  for (int i = 0; i < n; i++) {
    scanf("%d %d", &x, &y);
    if (i = 0) {
      Y = y;
      X = x;
    }
    if (Y == y && x < X) {
      X = x;
      Y = y;
    } else if (Y < y) {
      X = x;
      Y = y;
    }
  }

  printf("%d %d\n", X, Y);
  return 0;
}

Fixed submission:
#include <stdio.h>

int main() {

  int x, y, n;
  int X = 0, Y = 0;

  scanf("%d", &n);

  for (int i = 0; i < n; i++) {
    scanf("%d %d", &x, &y);
    if (i == 0) {
      Y = y;
      X = x;
    }
    if (Y == y && x < X) {
      X = x;
      Y = y;
    } else if (Y < y) {
      X = x;
      Y = y;
    }
  }

  printf("%d %d\n", X, Y);
  return 0;
}
Problem p00096 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>

using namespace std;

int ab[2001];

int main() {
  int n;

  while (cin >> n) {
    int ans = 0;

    for (int i = 0; i < 2001; i++)
      ab[i] = 0;

    for (int a = 0; a <= 1000; a++)
      for (int b = 0; b <= 1000; b++)
        ab[a + b]++;

    for (int c = 0; c <= 1000; c++)
      for (int d = 0; d <= 1000; d++)
        if (n - c - d >= 0)
          ans += ab[n - c - d];

    cout << ans << endl;
  }

  return 0;
}

Fixed submission:
#include <iostream>

using namespace std;

int ab[2001];

int main() {
  int n;

  while (cin >> n) {
    int ans = 0;

    for (int i = 0; i < 2001; i++)
      ab[i] = 0;

    for (int a = 0; a <= 1000; a++)
      for (int b = 0; b <= 1000; b++)
        ab[a + b]++;

    for (int c = 0; c <= 1000; c++)
      for (int d = 0; d <= 1000; d++)
        if (n - c - d >= 0 && n - c - d <= 2000)
          ans += ab[n - c - d];

    cout << ans << endl;
  }

  return 0;
}
Problem p00096 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
using namespace std;
int main() {
  int n;
  while (cin >> n) {
    int ans = 0;
    int x = 0;
    if (n > 3000)
      x = n - 3000;

    for (int i = x; i < 1001 && i <= n; i++) {
      // cout<<i<<"-"<<endl;
      int y = 0;
      if (n - i > 2000)
        y = n - i - 2000;

      for (int j = y; j < 1001 && i + j <= n; j++) {
        // cout<<j<<"--"<<endl;
        // if(n-i-j>=2001)continue;
        int z = 0;
        if (n - i - j > 1000)
          z = n - i - j - 1000;

        for (int k = z; k < 1001 && i + j + k <= n; k++) {
          // cout<<k<<"---"<<endl;;
          ans++;
        }
      }
    }

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

Fixed submission:
#include <iostream>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
using namespace std;
int main() {
  int n;
  while (cin >> n) {
    int ans = 0;
    int x = 0;
    if (n > 3000)
      x = n - 3000;

    for (int i = x; i < 1001 && i <= n; i++) {
      // cout<<i<<"-"<<endl;
      int y = 0;
      if (n - i > 2000)
        y = n - i - 2000;

      for (int j = y; j < 1001 && i + j <= n; j++) {
        // cout<<j<<"--"<<endl;
        // if(n-i-j>=2001)continue;
        int z = 0;
        if (n - i - j > 1000)
          z = n - i - j - 1000;

        int zz = 1001;
        if (1001 > n - i - j + 1)
          zz = n - i - j + 1;

        ans += zz - z;
      }
    }

    cout << ans << endl;
  }
  return 0;
}
Problem p00096 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cstdio>
#include <iostream>
using namespace std;

int main() {
  int num[2001] = {0};

  for (int i = 0; i <= 1000; i++) {
    for (int j = 0; j <= 1000; j++) {
      num[i + j]++;
    }
  }
  int n;
  while (cin >> n, n) {
    int res = 0;
    for (int i = 0; i <= n; i++) {
      if (i > 2000 || n - i > 2000)
        continue;
      res += num[i] * num[n - i];
    }
    cout << res << endl;
  }
  return 0;
}

Fixed submission:
#include <cstdio>
#include <iostream>
using namespace std;

int main() {
  int num[2001] = {0};

  for (int i = 0; i <= 1000; i++) {
    for (int j = 0; j <= 1000; j++) {
      num[i + j]++;
    }
  }
  int n;
  while (cin >> n) {
    int res = 0;
    for (int i = 0; i <= n; i++) {
      if (i > 2000 || n - i > 2000)
        continue;
      res += num[i] * num[n - i];
    }
    cout << res << endl;
  }
  return 0;
}
Problem p00096 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL << 30)
#define LLINF (1LL << 60)
#define PI 3.14159265359
#define EPS 1e-12
#define int ll

signed main(void) {
  int n;
  while (cin >> n) {
    int a[2010] = {0};
    REP(i, 1001) REP(j, 1001) { a[i + j]++; }
    int ret = 0;
    REP(i, 1001) REP(j, 1001) {
      if (i + j <= n) {
        ret += a[n - i - j];
      }
    }
    cout << ret << endl;
  }

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL << 30)
#define LLINF (1LL << 60)
#define PI 3.14159265359
#define EPS 1e-12
#define int ll

signed main(void) {
  int n;
  while (cin >> n) {
    int a[5010] = {0};
    REP(i, 1001) REP(j, 1001) { a[i + j]++; }
    int ret = 0;
    REP(i, 1001) REP(j, 1001) {
      if (i + j <= n) {
        ret += a[n - i - j];
      }
    }
    cout << ret << endl;
  }

  return 0;
}
Problem p00096 (C++)

Buggy submission (status: Runtime Error):
#include <cstring>
#include <iostream>

using namespace std;

int dp[2000];

int main() {
  memset(dp, 0, sizeof(dp));
  for (int i = 0; i <= 1000; i++) {
    for (int j = 0; j <= 1000; j++) {
      dp[i + j]++;
    }
  }
  int n;
  while (cin >> n) {
    int ans = 0;
    for (int i = 0; i <= n; i++) {
      ans += dp[i] * dp[n - i];
    }
    cout << ans << endl;
  }
  return 0;
}

Fixed submission:
#include <cstring>
#include <iostream>

using namespace std;

int dp[4000];

int main() {
  memset(dp, 0, sizeof(dp));
  for (int i = 0; i <= 1000; i++) {
    for (int j = 0; j <= 1000; j++) {
      dp[i + j]++;
    }
  }
  int n;
  while (cin >> n) {
    int ans = 0;
    for (int i = 0; i <= n; i++) {
      ans += dp[i] * dp[n - i];
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p00096 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n;
  long r;
  while (cin >> n) {
    r = 0;
    for (int a = 0; a <= 1000; a++) {
      for (int b = 0; b <= 1000; b++) {
        for (int c = 0; c <= 1000; c++) {
          int d = n - a - b - c;
          if (d >= 0 && d <= 1000)
            r++;
        }
      }
    }
    cout << r << endl;
  }
  return (0);
}

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

int main() {
  int n;
  long r;
  while (cin >> n) {
    r = 0;
    for (int a = 0; a <= 1000; a++) {
      for (int b = 0; b <= 1000; b++) {
        int s = n - a - b;
        if (s <= 1000 && s >= 0) {
          r += s + 1;
        } else if (s <= 2000 && s > 1000) {
          r += 2001 - s;
        }
      }
    }
    cout << r << endl;
  }
  return (0);
}
Problem p00096 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cassert>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>

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

using namespace std;

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

int n, dp[2010];

int main() {
  rep(i, 1001) rep(j, 1001) dp[i + j]++;

  while (cin >> n) {

    ll ans = 0;
    rep(i, n + 1) ans += (ll)dp[i] * dp[n - i];
    cout << ans << endl;
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cassert>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>

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

using namespace std;

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

int n, dp[4010];

int main() {
  rep(i, 1001) rep(j, 1001) dp[i + j]++;

  while (cin >> n) {

    ll ans = 0;
    rep(i, n + 1) ans += (ll)dp[i] * dp[n - i];
    cout << ans << endl;
  }
  return 0;
}
Problem p00096 (C++)

Buggy submission (status: Runtime Error):
#include <cstring>
#include <iostream>

int half[2001]; // 0<=a, b<=1000 として a+b となる組み合わせの数

void makeSet() {
  memset(half, 0, sizeof(half));
  // 半分全列挙
  for (int i = 0; i <= 1000; ++i) {
    for (int j = 0; j <= 1000; ++j) {
      int k = i + j;
      ++half[k];
    }
  }
}

int solve(int n) {
  int num = 0;
  int max = n < 2000 ? n : 2000; // Counterが半分全列挙の上限を超えない為

  for (int i = 0; i <= max; ++i) {
    num +=
        half[i] *
        half[n - i]; // 左半分の組み合わせ * 右半分の組み合わせ = 全組み合わせ
  }
  return num;
}

int main() {
  makeSet();

  while (true) {
    int n;
    std::cin >> n;
    if (std::cin.eof())
      break;

    std::cout << solve(n) << std::endl;
  }
  return 0;
}

Fixed submission:
#include <cstring>
#include <iostream>

int half[2001]; // 0<=a, b<=1000 として a+b となる組み合わせの数

void makeSet() {
  memset(half, 0, sizeof(half));
  // 半分全列挙
  for (int i = 0; i <= 1000; ++i) {
    for (int j = 0; j <= 1000; ++j) {
      int k = i + j;
      ++half[k];
    }
  }
}

int solve(int n) {
  int num = 0;
  int max = n < 2000 ? n : 2000; // Counterが半分全列挙の上限を超えない為

  for (int i = 0; i <= max; ++i) {
    if (n - i <= 2000)
      num +=
          half[i] *
          half[n - i]; // 左半分の組み合わせ * 右半分の組み合わせ = 全組み合わせ
  }
  return num;
}

int main() {
  makeSet();

  while (true) {
    int n;
    std::cin >> n;
    if (std::cin.eof())
      break;

    std::cout << solve(n) << std::endl;
  }
  return 0;
}
Problem p00096 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

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

int dp[2020];

int main() {
  int n;
  rep(i, 1000) rep(j, 1000) { dp[i + j]++; }

  while (cin >> n) {
    int ans = 0;
    rep(i, n) ans += dp[i] * dp[n - i];

    cout << ans << endl;
  }
}

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

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

int dp[4040];

int main() {
  int n;
  rep(i, 1000) rep(j, 1000) { dp[i + j]++; }

  while (cin >> n) {
    int ans = 0;
    rep(i, n) ans += dp[i] * dp[n - i];

    cout << ans << endl;
  }
}
Problem p00096 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

vector<int> v;
int a[2001];

int main() {
  for (int i = 0; i <= 1000; i++) {
    for (int j = 0; j <= 1000; j++) {
      a[i + j]++;
    }
  }

  int n;
  while (~scanf("%d", &n)) {
    int res = 0;
    for (int i = 0; i <= n; i++) {
      res += a[i] * a[n - i];
    }
    printf("%d\n", res);
  }
}

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

vector<int> v;
int a[10001];

int main() {
  for (int i = 0; i <= 1000; i++) {
    for (int j = 0; j <= 1000; j++) {
      a[i + j]++;
    }
  }

  int n;
  while (~scanf("%d", &n)) {
    int res = 0;
    for (int i = 0; i <= n; i++) {
      res += a[i] * a[n - i];
    }
    printf("%d\n", res);
  }
}
Problem p00096 (C++)

Buggy submission (status: Runtime Error):
#include <cstring>
#include <iostream>

using namespace std;

int n;
int cnt[2020];

void setcnt() {
  memset(cnt, 0, sizeof(cnt));
  for (int i = 0; i <= 1000; i++)
    for (int j = 0; j <= 1000; j++)
      cnt[i + j]++;
}

void solve() {
  int ans = 0;
  for (int ab = 0; ab <= n; ab++) {
    ans += cnt[ab] * cnt[n - ab];
  }
  cout << ans << endl;
}

int main() {
  setcnt();

  while (cin >> n) {
    solve();
  }

  return 0;
}

Fixed submission:
#include <cstring>
#include <iostream>

using namespace std;

int n;
int cnt[4040];

void setcnt() {
  memset(cnt, 0, sizeof(cnt));
  for (int i = 0; i <= 1000; i++)
    for (int j = 0; j <= 1000; j++)
      cnt[i + j]++;
}

void solve() {
  int ans = 0;
  for (int ab = 0; ab <= n; ab++) {
    ans += cnt[ab] * cnt[n - ab];
  }
  cout << ans << endl;
}

int main() {
  setcnt();

  while (cin >> n) {
    solve();
  }

  return 0;
}