alexjercan/bugnet huggingface dataset:
Problem p00706 (C++) — buggy submission, verdict: Runtime Error

// AOJ 1125

#include <iostream>

using namespace std;

// x, i, w, s
// y, j, h, t

int main(void) {
  int n;
  while (cin >> n, n) {
    int w, h, x, y, s, t;
    cin >> w >> h;
    int field[w][h];

    for (int i = 0; i < w; i++) {
      for (int j = 0; j < h; j++) {
        field[i][j] = 0;
      }
    }
    for (int i = 0; i < n; i++) {
      cin >> x >> y;
      x--;
      y--;
      field[x][y] = 1;
    }
    cin >> s >> t;

    int ret = 0;
    for (int i = 0; i <= (w - s); i++) {
      for (int j = 0; j <= (h - t); j++) {
        int cnt = 0;
        // cout << "start : " << i+1 << " " << j+1 << endl;
        // cout << "end   : " << i + s << " " << j + t << endl;
        for (int k = 0; k < s; k++) {
          for (int l = 0; l < t; l++) {
            cnt += field[i + k][j + l];
          }
        }
        ret = max(ret, cnt);
      }
    }

    cout << ret << endl;
  }
}

Error: -11

Fixed submission:

// AOJ 1125

#include <iostream>

using namespace std;

// x, i, w, s
// y, j, h, t

int main(void) {
  int n;
  while (cin >> n, n) {
    int w, h, x, y, s, t;
    cin >> w >> h;
    int field[w][h];

    for (int i = 0; i < w; i++) {
      for (int j = 0; j < h; j++) {
        field[i][j] = 0;
      }
    }
    for (int i = 0; i < n; i++) {
      cin >> x >> y;
      field[x][y] = 1;
    }
    cin >> s >> t;

    int ret = 0;
    for (int i = 0; i < (w - s); i++) {
      for (int j = 0; j < (h - t); j++) {
        int cnt = 0;
        for (int k = 0; k < s; k++) {
          for (int l = 0; l < t; l++) {
            cnt += field[i + k][j + l];
          }
        }
        ret = max(ret, cnt);
      }
    }

    cout << ret << endl;
  }
}
Problem p00706 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;
int h, w, k, l, m, a, b, s, t, u, v, i, j, x[1000][1000];
int main() {
  while (true) {
    memset(x, 0, sizeof(x));
    v = 0;
    cin >> k;
    if (k == 0) {
      break;
    }
    cin >> w >> h;
    for (i = 0; i < k; i++) {
      cin >> a >> b;
      x[a][b] = 1;
    }
    cin >> s >> t;
    for (i = 1; i <= w; i++) {
      for (j = 1; j <= h; j++) {
        u = 0;
        for (l = 0; l < s; l++) {
          for (m = 0; m < t; m++) {
            if (x[i + l][j + m] == 1) {
              u++;
            }
          }
        }
        v = max(v, u);
      }
    }
    cout << v << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;
int h, w, k, l, m, a, b, s, t, u, v, i, j, x[1000][1000];
int main() {
  while (true) {
    memset(x, 0, sizeof(x));
    v = 0;
    cin >> w >> h;
    if (w == 0) {
      break;
    }
    cin >> k;
    for (i = 0; i < k; i++) {
      cin >> a >> b;
      x[a][b] = 1;
    }
    cin >> s >> t;
    for (i = 0; i < w; i++) {
      for (j = 0; j < h; j++) {
        u = 0;
        for (l = 0; l < s; l++) {
          for (m = 0; m < t; m++) {
            if (x[i + l][j + m] == 1) {
              u++;
            }
          }
        }
        v = max(v, u);
      }
    }
  }
}
Problem p00706 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  int i, j, n, w, h, s, t, wx, hy, map[101][101];
  while (1) {
    cin >> n;
    if (n == 0)
      break;
    int datax[501];
    int datay[501];
    cin >> w >> h;
    for (i = 1; i <= n; i++) {
      cin >> wx >> hy;
      map[hy][wx] = 1;
      datax[i] = wx;
      datay[i] = hy;
    }
    cin >> s >> t;
    int max = -1;
    for (i = 1; i <= h; i++) {
      for (j = 1; j <= w; j++) {
        int count = 0;
        for (int k = 1; k <= n; k++) {
          if (datay[k] >= i && datay[k] < i + t) {
            if (datax[k] >= j && datax[k] < j + s) {
              count++;
              if (max < count)
                max = count;
            }
          }
        }
      }
    }
    cout << max << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int i, j, n, w, h, s, t, wx, hy, map[101][101];
  while (1) {
    cin >> n;
    if (n == 0)
      break;
    int datax[101];
    int datay[101];
    cin >> w >> h;
    for (i = 1; i <= n; i++) {
      cin >> wx >> hy;
      map[hy][wx] = 1;
      datax[i] = wx;
      datay[i] = hy;
    }
    cin >> s >> t;
    int max = -1;
    for (i = 1; i <= h; i++) {
      for (j = 1; j <= w; j++) {
        int count = 0;
        for (int k = 1; k <= n; k++) {
          if (datay[k] >= i && datay[k] < i + t) {
            if (datax[k] >= j && datax[k] < j + s) {
              count++;
              if (max < count)
                max = count;
            }
          }
        }
      }
    }
    cout << max << endl;
  }
  return 0;
}
Problem p00706 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define lp(i, n) for (int i = 0; i < n; i++)

int main() {
  while (1) {
    int n;
    int a[100][100];
    cin >> n;
    if (n == 0)
      break;
    lp(i, 100) {
      lp(k, 100) { a[i][k] = 0; }
    }
    int w, h;
    cin >> w >> h;
    lp(i, n) {
      int x, y;
      cin >> x >> y;
      a[x - 1][y - 1] = 1;
    }
    int aw, ah;
    cin >> aw >> ah;
    w -= aw;
    h -= ah;
    int sum = 0, ans = 0;
    lp(i, w + 1) {
      lp(j, h + 1) {
        sum = 0;
        lp(k, aw) {
          lp(l, ah) { sum += a[i + k][j + l]; }
        }
        if (sum > ans)
          ans = sum;
      }
    }
    cout << ans << endl;
  }
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define lp(i, n) for (int i = 0; i < n; i++)

int main() {
  while (1) {
    int n;
    int a[100][100];
    cin >> n;
    if (n == 0)
      break;
    lp(i, 100) {
      lp(k, 100) { a[i][k] = 0; }
    }
    int w, h;
    cin >> w >> h;
    lp(i, n) {
      int x, y;
      cin >> x >> y;
      a[x - 1][y - 1] = 1;
    }
    int aw, ah;
    cin >> aw >> ah;
    w -= aw;
    h -= ah;
    int sum = 0, ans = 0;
    lp(i, w) {
      lp(j, h) {
        sum = 0;
        lp(k, aw) {
          lp(l, ah) { sum += a[i + h][j + l]; }
        }
        if (sum > ans)
          ans = sum;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p00706 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <vector>
using namespace std;

int main(void) {

  int n;
  while (cin >> n) {
    if (n == 0)
      break;

    int w, h;
    cin >> w >> h;
    vector<vector<bool>> a(h, vector<bool>(w, false));
    for (int i = 0; i < n; i++) {
      int x, y;
      cin >> x >> y;
      a[y - 1][x - 1] = true;
    }
    int s, t;
    cin >> s >> t;

    int mx = 0;
    for (int i = 0; i <= h - t; i++) {
      for (int j = 0; j <= w - s; j++) {
        int cnt = 0;
        for (int k = 0; k < t; k++) {
          for (int l = 0; l < s; l++) {
            if (a[i + k][j + l])
              cnt++;
          }
        }
        mx = max(mx, cnt);
      }
    }
    cout << mx << endl;
  }

  return 0;
}

//

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <vector>
using namespace std;

int main(void) {

  int n;
  while (cin >> n) {
    if (n == 0)
      break;

    cerr << endl;
    int w, h;
    cin >> w >> h;
    vector<vector<bool>> a(h, vector<bool>(w, false));
    for (int i = 0; i < n; i++) {
      int x, y;
      cin >> x >> y;
      a[y - 1][x - 1] = true;
    }
    int s, t;
    cin >> s >> t;

    int mx = 0;
    for (int i = 0; i <= h - t; i++) {
      for (int j = 0; j <= w - s; j++) {
        int cnt = 0;
        for (int k = 0; k < t; k++) {
          for (int l = 0; l < s; l++) {
            if (a[i + k][j + l])
              cnt++;
          }
        }
        mx = max(mx, cnt);
      }
    }
    cout << mx << endl;
  }

  return 0;
}

//
Problem p00706 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, k, n) for (int i = (k); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define INF 114514810
#define ll long long
#define ALL(a) (a).begin(), (a).end()
#define SORT(v) sort(ALL(v))
// #define scanf scanf_s
typedef pair<int, int> P;

int n;
int w, h;
int tizu[300][300];
int main() {
  while (cin >> n, n) {
    memset(tizu, 0, sizeof(tizu));
    cin >> w >> h;
    REP(i, n) {
      int x, y;
      cin >> x >> y;
      tizu[y - 1][x - 1] = 1;
    }
    int s, t;
    cin >> s >> t;
    int ans = 0;
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        int cnt = 0;
        REP(k, t) REP(l, s) { cnt += tizu[k + i][l + j]; }
        ans = max(cnt, ans);
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, k, n) for (int i = (k); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define INF 114514810
#define ll long long
#define ALL(a) (a).begin(), (a).end()
#define SORT(v) sort(ALL(v))
// #define scanf scanf_s
typedef pair<int, int> P;

int n;
int w, h;
int tizu[105][105];
int main() {
  while (cin >> n, n) {
    memset(tizu, 0, sizeof(tizu));
    cin >> w >> h;
    REP(i, n) {
      int x, y;
      cin >> x >> y;
      tizu[y - 1][x - 1] = 1;
    }
    int s, t;
    cin >> s >> t;
    int ans = 0;
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        int cnt = 0;
        REP(k, t) REP(l, s) { cnt += tizu[k + i][l + j]; }
        ans = max(cnt, ans);
      }
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p00706 (C++) — buggy submission, verdict: Runtime Error

// #define _GRIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
vector<vector<int>> Z;

int main() {
  int n, w, h, x, y, s, t;

  while (cin >> n, n) {
    cin >> w >> h;
    Z.resize(w);
    rep(i, w) Z[i].resize(h);
    rep(i, w) fill(Z[i].begin(), Z[i].end(), 0);

    rep(i, n) {
      cin >> x >> y;
      Z[x - 1][y - 1] = 1;
    }

    cin >> s >> t;
    int ans = 0;

    rep(i, w - s + 1) {
      rep(j, h - t + 1) {
        int ans_ = 0;
        rep(a, s) rep(b, t) ans_ += Z[i + a][j + b];
        ans = max(ans, ans_);
      }
    }

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

Error: 0

Fixed submission:

// #define _GRIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int n, w, h, x, y, s, t;
vector<vector<int>> Z;

int get_fruit(int si, int ei, int sj, int ej) {
  int sumval = 0;
  if (ei >= h || ej >= w)
    return -1;

  // cout << "start" << endl;
  for (int i = si; i < ei; i++) {
    for (int j = sj; j < ej; j++) {
      // cout << i << ',' << j << endl;
      sumval += Z[i][j];
    }
  }
  // cout << "finish with sumval: " << sumval << endl;

  return sumval;
}

int main() {

  while (cin >> n, n) {
    cin >> w >> h;
    Z.resize(n);
    rep(i, h) Z[i].resize(w);

    rep(i, n) {
      cin >> x >> y;
      Z[--y][--x] = 1;
    }

    cin >> s >> t;
    int ans = 0;

    rep(i, h) {
      rep(j, w) {
        // ans = max(ans, get_fruit(i, i+s, j, j+t));
        ans = max(ans, get_fruit(i, i + t, j, j + s));
      }
    }

    cout << ans << endl;
  }
  return 0;
}
Problem p00706 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>

using namespace std;

int N, W, H, S, T;
int x[507], y[507];
int map[507][507];

int solve() {
  int res = 0;
  for (int i = 0; i <= W - S + 1; i++) {
    for (int j = 0; j <= H - T + 1; j++) {

      int tmp = 0;
      for (int g = i; g < i + S; g++) {
        for (int f = j; f < j + T; f++) {
          if (map[g][f] == 1)
            tmp++;
        }
      }

      res = max(res, tmp);
    }
  }
  return res;
}

void init() {
  for (int i = 0; i < 507; i++) {
    x[i] = 0;
    y[i] = 0;
    for (int j = 0; j < 507; j++) {
      map[i][j] = 0;
    }
  }
}

int main() {
  while (1) {
    init();
    scanf("%d", &N);
    if (N == 0)
      break;
    scanf("%d%d", &W, &H);
    W--;
    H--;
    for (int i = 0; i < N; i++) {
      scanf("%d%d", &x[i], &y[i]);
      map[x[i] - 1][y[i] - 1] = 1;
    }

    scanf("%d%d", &S, &T);

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

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>

using namespace std;

int N, W, H, S, T;
int x[107], y[107];
int map[107][107];

int solve() {
  int res = 0;
  for (int i = 0; i <= W - S + 1; i++) {
    for (int j = 0; j <= H - T + 1; j++) {

      int tmp = 0;
      for (int g = i; g < i + S; g++) {
        for (int f = j; f < j + T; f++) {
          if (map[g][f] == 1)
            tmp++;
        }
      }

      res = max(res, tmp);
    }
  }
  return res;
}

void init() {
  for (int i = 0; i < 107; i++) {
    x[i] = 0;
    y[i] = 0;
    for (int j = 0; j < 107; j++) {
      map[i][j] = 0;
    }
  }
}

int main() {
  while (1) {
    init();
    scanf("%d", &N);
    if (N == 0)
      break;
    scanf("%d%d", &W, &H);
    W--;
    H--;
    for (int i = 0; i < N; i++) {
      scanf("%d%d", &x[i], &y[i]);
      map[x[i] - 1][y[i] - 1] = 1;
    }

    scanf("%d%d", &S, &T);

    printf("%d\\n", solve());
  }
  return 0;
}
Problem p00706 (C++) — buggy submission, verdict: Runtime Error

#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main() {
  int i, j, k, l;
  int n;
  int w, h;
  int ww, hh;
  int ans, sum;
  int a[101][101];

  int p, q;

  while (1) {
    scanf("%d", &n);
    if (n == 0) {
      break;
    } else {
      ans = 0;
      for (i = 0; i < 101; i++) {
        for (j = 0; j < 101; j++) {
          a[i][j] = 0;
        }
      }

      scanf("%d %d", &w, &h);

      for (i = 0; i < n; i++) {
        int x, y;
        scanf("%d %d", &x, &y);
        a[x - 1][y - 1] = 1;
      }

      scanf("%d %d", &ww, &hh);

      for (i = 0; i < (w - ww + 1); i++) {
        for (j = 0; j < (h - hh + 1); j++) {
          sum = 0;
          for (k = i; k < (i + ww); k++) {
            for (l = j; l < (j + hh); l++) {
              sum += a[k][l];
            }
          }
          if (ans < sum) {
            ans = sum;
          }
        }
      }
    }
    printf("%d\\n", ans);
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main() {
  int i, j, k, l;
  int n;
  int w, h;
  int ww, hh;
  int ans, sum;
  int a[100][100];

  while (1) {
    scanf("%d", &n);
    if (n == 0) {
      break;
    } else {
      ans = 0;
      for (i = 0; i < 100; i++) {
        for (j = 0; j < 100; j++) {
          a[i][j] = 0;
        }
      }

      for (i = 0; i < n; i++) {
        int x, y;
        scanf("%d %d", &x, &y);
        a[x - 1][y - 1] = 1;
      }

      scanf("%d %d", &ww, &hh);

      for (i = 0; i < (w - ww); i++) {
        for (j = 0; j < (h - hh); j++) {
          sum = 0;
          for (k = i; k < (i + ww); k++) {
            for (l = j; l < (j + hh); l++) {
              sum += a[k][l];
            }
          }
          if (ans < sum) {
            ans = sum;
          }
        }
      }
    }
    printf("%d\\n", ans);
  }
  return 0;
}
Problem p00706 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define REP(i, N) for (ll i = 0; i < N; ++i)
#define FOR(i, a, b) for (ll i = a; i < b; ++i)
#define ALL(a) (a).begin(), (a).end()
#define pb push_back
#define INF (long long)1000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main(void) {
  while (true) {
    int N, W, H;
    cin >> N;
    if (N == 0)
      break;
    cin >> W >> H;
    vector<vector<bool>> m(H, vector<bool>(W, false));
    vector<vector<int>> wa(H + 1, vector<int>(W + 1, 0));
    REP(i, N) {
      int x, y;
      cin >> x >> y;
      --x;
      --y;
      m[y][x] = true;
    }
    REP(i, H) {
      REP(j, W) { wa[i + 1][j + 1] += wa[i + 1][j] + (int)m[i][j]; }
    }
    REP(i, H) {
      REP(j, W) { wa[i + 1][j + 1] += wa[i][j + 1]; }
    }
    int S, T;
    cin >> S >> T;
    int ans = 0;
    REP(i, H - T + 1) {
      REP(j, W - S + 1) {
        ans =
            max(ans, wa[T + i][S + j] - wa[T + i][j] - wa[i][S + j] + wa[i][j]);
      }
    }
    cout << ans << endl;
  }
}

Error: -6
munmap_chunk(): invalid pointer


Fixed submission:

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define REP(i, N) for (ll i = 0; i < N; ++i)
#define FOR(i, a, b) for (ll i = a; i < b; ++i)
#define ALL(a) (a).begin(), (a).end()
#define pb push_back
#define INF (long long)1000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main(void) {
  while (true) {
    int N, W, H;
    cin >> N;
    if (N == 0)
      break;
    cin >> W >> H;
    vector<vector<bool>> m(H, vector<bool>(W, false));
    vector<vector<int>> wa(H + 1, vector<int>(W, 0));
    REP(i, N) {
      int x, y;
      cin >> x >> y;
      --x;
      --y;
      m[y][x] = true;
    }
    REP(i, H) {
      REP(j, W) { wa[i + 1][j + 1] += wa[i + 1][j] + (int)m[i][j]; }
    }
    REP(i, H) {
      REP(j, W) { wa[i + 1][j + 1] += wa[i][j + 1]; }
    }
    int S, T;
    cin >> S >> T;
    int ans = 0;
    REP(i, H - T + 1) {
      REP(j, W - S + 1) {
        ans =
            max(ans, wa[T + i][S + j] - wa[T + i][j] - wa[i][S + j] + wa[i][j]);
      }
    }
    cout << ans << endl;
  }
}
Problem p00706 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int main(void) {
  int n;
  while (cin >> n && n) {
    int w, h;
    cin >> w >> h;
    bool field[w][h];
    fill(field[0], field[w], 0);
    for (int i = 0; i < n; ++i) {
      int x, y;
      cin >> x >> y;
      field[x - 1][y - 1] = 1;
    }
    int s, t;
    cin >> s >> t;
    int res = 0;
    for (int sy = 0; sy <= h - t; ++sy) {
      for (int sx = 0; sx <= w - s; ++sx) {
        int count = 0;
        for (int dy = 0; dy < t; ++dy) {
          for (int dx = 0; dx < s; ++dx) {
            count += field[sx + dx][sy + dy];
          }
        }
        res = max(res, count);
      }
    }
    cout << res << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;
int main(void) {
  int n;
  while (cin >> n && n) {
    int w, h;
    cin >> w >> h;
    bool field[w][h];
    fill(field[0], field[w], 0);
    for (int i = 0; i < n; ++i) {
      int x, y;
      cin >> x >> y;
      field[x][y] = 1;
    }
    int s, t;
    cin >> s >> t;
    int res = 0;
    for (int sy = 0; sy <= h - t; ++sy) {
      for (int sx = 0; sx <= w - s; ++sx) {
        int count = 0;
        for (int dy = 0; dy < t; ++dy) {
          for (int dx = 0; dx < s; ++dx) {
            count += field[sx + dx][sy + dy];
          }
        }
        res = max(res, count);
      }
    }
    cout << res << endl;
  }
  return 0;
}
Problem p00706 (C++) — buggy submission, verdict: Runtime Error

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1125

#include <algorithm>
#include <iostream>
#include <stdio.h>
using namespace std;

int N, W, H, S, T;
bool field[110][110];

void init() { fill(&field[0][0], &field[0][0] + 110 * 110, false); }

int trees(int o_x, int o_y) {
  int count = 0;
  for (int i = o_x; i < o_x + S; i++) {
    for (int j = o_y; j < o_y + T; j++) {
      if (field[i][j]) {
        count++;
      }
    }
  }
  return count++;
}

int main() {
  while (scanf("%d", &N) != EOF && N) {
    init();
    scanf("%d%d", &W, &H);
    int x, y;
    for (int i = 0; i < N; i++) {
      scanf("%d%d", &x, &y);
      x--;
      y--; // 0からにする。
      field[x][y] = true;
    }
    scanf("%d%d", &S, &T);
    int max = 0;
    for (int i = 0; i + S <= W; i++) {
      for (int j = 0; j + T <= H; j++) {
        int temp = trees(i, j);
        if (max < temp) {
          max = temp;
        }
      }
    }
    printf("%d\\n", max);
  }
}

Error: -11

Fixed submission:

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1125

#include <algorithm>
#include <iostream>
#include <stdio.h>
using namespace std;

int N, W, H, S, T;
bool field[110][110];

void init() { fill(&field[0][0], &field[110][110], false); }

int trees(int o_x, int o_y) {
  int count = 0;
  for (int i = o_x; i < o_x + S; i++) {
    for (int j = o_y; j < o_y + T; j++) {
      if (field[i][j]) {
        count++;
      }
    }
  }
  return count++;
}

int main() {
  while (scanf("%d", &N) != EOF && N) {
    init();
    scanf("%d%d", &W, &H);
    int x, y;
    for (int i = 0; i < N; i++) {
      scanf("%d%d", &x, &y);
      x--;
      y--; // 0からにする。
      field[x][y] = true;
    }
    scanf("%d%d", &S, &T);
    int max = 0;
    for (int i = 0; i + S <= W; i++) {
      for (int j = 0; j + T <= H; j++) {
        int temp = trees(i, j);
        if (max < temp) {
          max = temp;
        }
      }
    }
    printf("%d\\n", max);
  }
}
Problem p00707 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)

char C[71][71];
string memo[71][71];
int W, H;
bool isNum(char c) {
  if (c >= '0' && c <= '9')
    return true;
  else
    return false;
}
string max_str(string a, string b) {
  if (a.size() > b.size())
    return a;
  if (a.size() < b.size())
    return b;
  return max(a, b);
}
string dfs(int y, int x) {
  if (memo[y][x] != "")
    return memo[y][x];
  if ((y + 1 >= H || !isNum(C[y + 1][x])) &&
      (x + 1 >= W || !isNum(C[y][x + 1]))) {
    memo[y][x] = C[y][x];
    return memo[y][x];
  }
  string ans = "";
  if (y + 1 < H && isNum(C[y + 1][x]))
    ans = max_str(ans, C[y][x] + dfs(y + 1, x));
  if (x + 1 < W && isNum(C[y][x + 1]))
    ans = max_str(ans, C[y][x] + dfs(y, x + 1));
  memo[y][x] = ans;
  return memo[y][x];
}

int main(void) {
  while (cin >> W >> H && W) {
    rep(i, H) rep(j, W) {
      cin >> C[i][j];
      memo[i][j] = "";
    }
    string ans;
    for (int i = H - 1; i >= 0; --i) {
      for (int j = W - 1; j >= 0; --j) {
        if (isNum(C[i][j]) && C[i][j] != '0') {
          ans = max_str(ans, dfs(i, j));
        }
      }
    }
    cout << ans << endl;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)

char C[71][71];
int W, H;
bool isNum(char c) {
  if (c >= '0' && c <= '9')
    return true;
  else
    return false;
}
string max_str(string a, string b) {
  if (a.size() > b.size())
    return a;
  if (a.size() < b.size())
    return b;
  rep(i, a.size()) {
    if (a[i] > b[i])
      return a;
    if (a[i] < b[i])
      return b;
  }
  return a;
}
string dfs(int y, int x, string sum) {
  if ((y + 1 >= H || !isNum(C[y + 1][x])) &&
      (x + 1 >= W || !isNum(C[y][x + 1]))) {
    return sum + C[y][x];
  }
  string down, right;
  if (y + 1 < H && isNum(C[y + 1][x])) {
    if (sum == "" && C[y][x] == '0')
      down = dfs(y + 1, x, sum);
    else
      down = dfs(y + 1, x, sum + C[y][x]);
  }
  if (x + 1 < W && isNum(C[y][x + 1])) {
    if (sum == "" && C[y][x] == '0')
      right = dfs(y, x + 1, sum);
    else
      right = dfs(y, x + 1, sum + C[y][x]);
  }
  return max_str(down, right);
}

int main(void) {
  while (cin >> W >> H && W) {
    rep(i, H) rep(j, W) cin >> C[i][j];
    string ans;
    rep(i, H) rep(j, W) {
      if (isNum(C[i][j]))
        ans = max_str(ans, dfs(i, j, ""));
    }
    cout << ans << endl;
  }
}