alexjercan/bugnet huggingface dataset:
Problem p00092 (C++) — buggy submission, verdict: 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 = 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;
}

Error: TLE

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 = 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, verdict: 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 = 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;
}

Error: TLE

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 = 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, verdict: 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, 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;
}

Error: 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, 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;
}
Problem p00092 (C++) — buggy submission, verdict: Runtime Error

#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;
}


Error: 0

Fixed submission:

#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;
}
Problem p00092 (C++) — buggy submission, verdict: 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);
  }
}

Error: TLE

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, verdict: 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[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);
  }
}

Error: 0

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[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);
  }
}
Problem p00092 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <stdlib.h>

using namespace std;

int search(int **a, int s, int t, int c, int n) {
  if ((s + c) >= n || (t + c) >= n) {
    return 1;
  }

  for (int i = 0; i <= c; i++) {
    if (a[s + c][t + i] == 1 || a[s + i][t + c] == 1) {
      return 1;
    }
  }

  return (1 + search(a, s, t, (c + 1), n));
}

int main(int argc, char **argv) {
  int n, tmp, c, **array;
  char w;
  while (1) {
    cin >> n;
    if (n == 0) {
      break;
    }

    array = (int **)calloc(n, sizeof(int));
    for (int i = 0; i < n; i++) {
      array[i] = (int *)calloc(n, sizeof(int));
    }

    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        cin >> w;
        array[i][j] = (w == '.') ? 0 : 1;
      }
    }

    c = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (array[i][j] == 0) {
          tmp = search(array, i, j, 1, n);

          if (tmp > c) {
            c = tmp;
          }
        }
      }
    }
    cout << c << endl;

    for (int i = 0; i < n; i++) {
      free(array[i]);
    }
    free(array);
  }

  return 0;
}

Error: -6
double free or corruption (out)


Fixed submission:

#include <iostream>
#include <stdlib.h>

using namespace std;

int search(char **a, int s, int t, int c, int n) {
  if ((s + c) >= n || (t + c) >= n) {
    return 0;
  }

  for (int i = 0; i <= c; i++) {
    if (a[s + c][t + i] == '*' || a[s + i][t + c] == '*') {
      return 1;
    }
  }

  return (1 + search(a, s, t, (c + 1), n));
}

int main(int argc, char **argv) {
  int n, tmp, c;
  char **array;

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

    array = (char **)calloc(n, sizeof(char));
    for (int i = 0; i < n; i++) {
      array[i] = (char *)calloc(n, sizeof(char));
      for (int j = 0; j < n; j++) {
        cin >> array[i][j];
      }
    }

    c = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (array[i][j] == '.') {
          tmp = search(array, i, j, 1, n);

          if (tmp > c) {
            c = tmp;
          }
        }
      }
    }
    cout << c << endl;

    for (int i = 0; i < n; i++) {
      free(array[i]);
    }
    free(array);
  }

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

#include <iostream>
using namespace std;

int main(void) {
  int a, b;
  int flag;
  int flag2 = 0;

  while (1) {
    cin >> a >> b;
    if (a == 0 && b == 0)
      break;
    flag = 0;
    if (flag2 != 0)
      cout << endl;

    for (int i = a; i <= b; i++) {
      if (i % 4 == 0 && i % 100 != 0 || i % 400 == 0) {
        cout << i << endl;
        flag = 1;
      }
    }
    if (flag == 0)
      cout << "NA" << endl;
    flag2 = 1;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main(void) {
  int a, b;
  int flag;

  while (1) {
    cin >> a >> b;
    flag = 0;

    for (int i = a; i <= b; i++) {
      if (i % 4 == 0 && i % 400 != 0 || i % 100 == 0) {
        cout << i << endl;
        flag = 1;
      }
    }
    if (flag == 0)
      cout << "NA" << endl;
  }
  return 0;
}
Problem p00093 (C++) — buggy submission, verdict: Runtime Error

#include <stdbool.h>
#include <stdio.h>

bool is_leap_year(int y);
int get_leap_years(int *a, int b, int c);

int main(void) {
  int leap_years_list[1000]; // A.D. 0 - A.D. 3000
                             // の間に閏年は高々1000個しかない

  bool first_set = true; // 一つ目のセットの前にだけは改行を入れてはいけないので

  while (true) {
    int year_begin, year_end;

    // 読み込み
    scanf("%d %d", &year_begin, &year_end);

    // 終了判定
    if (year_begin == 0 && year_end == 0) {
      break;
    }

    // 閏年を計算する
    int leap_years_count =
        get_leap_years(leap_years_list, year_begin, year_end);

    // セットとセットの間には空行を入れる
    if (first_set) {
      first_set = false;
    } else {
      putchar('\\n'); // putcharは一文字だけ出力する関数です
    }

    // 閏年を出力
    if (leap_years_count == 0) {
      puts("NA"); // putsは与えられた文字列を出力した後改行する関数です
    } else {
      for (int i = 0; i < leap_years_count; i++) {
        printf("%d\\n", leap_years_list[i]);
      }
    }
  }
}

bool is_leap_year(int y) {
  if (y % 400 == 0) {
    return true;
  } else if (y % 100 == 0) {
    return false;
  } else {
    return y % 4 == 0;
  }
}

int get_leap_years(int *a, int b, int c) {
  int i = 0;
  for (int year = b; year <= c; ++year) {
    if (is_leap_year(year)) {
      a[i] = year;
      ++i;
    }
  }
  return i;
}

Error: -11

Fixed submission:

#include <stdbool.h>
#include <stdio.h>

bool is_leap_year(int y);
int get_leap_years(int *a, int b,
                   int c); // a = leap_year_list , b = year_begin , c = year_end

int main() {
  int leap_years_list[1000]; // A.D. 0 - A.D. 3000
                             // の間に閏年は高々1000個しかない

  bool first_set = true; // 一つ目のセットの前にだけは改行を入れてはいけないので

  while (true) {
    int year_begin, year_end;

    // 読み込み
    scanf("%d %d", &year_begin, &year_end);

    // 終了判定
    if (year_begin == 0 && year_end == 0) {
      break;
    }

    // 閏年を計算する
    int leap_years_count =
        get_leap_years(leap_years_list, year_begin, year_end);

    // セットとセットの間には空行を入れる
    if (first_set) {
      first_set = false;
    } else {
      putchar('\\n'); // putcharは一文字だけ出力する関数です
    }

    // 閏年を出力
    if (leap_years_count == 0) {
      puts("NA"); // putsは与えられた文字列を出力した後改行する関数です
    } else {
      for (int i = 0; i < leap_years_count; i++) {
        printf("%d\\n", leap_years_list[i]);
      }
    }
  }
}

bool is_leap_year(int y) {
  if (y % 400 == 0) {
    return true;
  } else if (y % 100 == 0) {
    return false;
  } else {
    return y % 4 == 0;
  }
}

int get_leap_years(int *a, int b, int c) {
  int i = 0;
  for (int year = b; year <= c; ++year) {
    while (is_leap_year(year)) {
      *a = year; // 引数として与えられた配列に閏年を表す数字を格納
      ++a;
      ++i;
    }
  }
  return i;
}
Problem p00093 (C++) — buggy submission, verdict: 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 (!a) {
      break;
    }
    if (cnt2) {
      cout << endl;
    }
    cnt2++;
    hantei(a, b);
  }
}

Error: TLE

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 (cnt2) {
      cout << endl;
    }
    cnt2++;
    hantei(a, b);
  }
}
Problem p00093 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>

int count_number(void);

int main(void) {

  int a[15]; // 15は適当　要素数はわからないが配列を作りたかった
  int b[15];
  int dataset_number = 0;
  while (1) {
    scanf("%d %d", &a[dataset_number], &b[dataset_number]);
    if (a[dataset_number] == 0 && b[dataset_number] == 0) {
      break;
    }
    dataset_number++;
  }
  int j = 0;
  while (j < dataset_number - 1) {
    int leapyear_number = 0;
    int i = a[j];
    while (i <= b[j]) {
      if ((((i % 4) == 0) && ((i % 100) != 0)) || ((i % 400) == 0)) {
        printf("%d\\n", i);
        leapyear_number++;
      }
      i++;
    }
    if (leapyear_number == 0) {
      printf("NA\\n\\n");
    } else {
      printf("\\n");
    }
    j++;
  }
  // j=dataset_number-1の時のみ最後\\がひとつ
  if (dataset_number > 0) {
    int leapyear_number = 0;
    int i = a[dataset_number - 1];
    while (i <= b[dataset_number - 1]) {
      if ((((i % 4) == 0) && ((i % 100) != 0)) || ((i % 400) == 0)) {
        printf("%d\\n", i);
        leapyear_number++;
      }
      i++;
    }
    if (leapyear_number == 0) {
      printf("NA\\n");
    } else {
    }
  }
}

Error: TLE

Fixed submission:

#include <stdio.h>

int count_number(void);

int main(void) {
  while (1) {
    int a;
    int b;
    scanf("%d %d", &a, &b);
    if (a == 0 && b == 0) {
      break;
    } else {
      int count = 0;
      for (int i = a; i++; i <= b) {
        if (((i % 4) == 0) && ((i % 100) != 0) && ((i % 400) == 0)) {
          printf("%d\\n", i);
          count++;
        }
      }
      if (count == 0) {
        printf("NA\\n\\n");
      } else {
        printf("\\n");
      }
    }
  }
}
Problem p00093 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

bool judgeUruyear(int year) {

  if (year % 400 == 0) {
    return true;
  } else if (year % 100 == 0) {
    return false;
  } else if (year % 4 == 0) {
    return true;
  } else {
    return false;
  }
}
int a = 1;
void printUruyear(int year_begin, int year_end) {
  if (a == 0) {
    std::cout << std::endl;
  }
  a = 0;
  int count_year = 0;

  // kono for loop no jyouken-siki ha "=" hituyou
  for (int i = year_begin; i <= year_end; i++) {

    if (judgeUruyear(i)) {

      count_year += 1;
      std::cout << i << std::endl;
    }
  }

  if (count_year == 0) {
    std::cout << "NA" << std::endl;
  }
}

int main() {
  int year_begin, year_end;

  for (; true;) {

    std::cin >> year_begin >> year_end;

    if (year_begin == 0 && year_end == 0) {
      break;
    }

    printUruyear(year_begin, year_end);
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

bool judge_uruyear(int year) {
  if (year % 400 == 0) {
    return true;
  } else if (year % 100 == 0) {
    return false;
  } else if (year % 4 == 0) {
    return true;
  } else {
    return false;
  }
}

void print_uruyear(int year_begin, int year_end) {
  int count_year = 0;
  for (int i = year_begin; i < year_end; i++) {
    if (judge_uruyear(i)) {
      count_year += 1;
      std::cout << i << std::endl;
    }
    if (count_year == 0) {
      std::cout << "NA" << std::endl;
    }
  }
}

int main() {
  int year_begin, year_end;
  std::cin >> year_begin >> year_end;

  while (year_begin != 0 || year_end != 0) {

    print_uruyear(year_begin, year_end);
  }

  return 0;
}