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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <queue>
#include <vector>

using namespace std;
#define rep2(x, from, to) for (int x = (from); (x) < (to); (x)++)
#define rep(x, to) rep2(x, 0, to)
#define INF 100000000
int table[100][1000];
int x, y, s;
int ans;
int ss(int num, int tax) {
  int k = num * (100 + tax);
  return k / 100;
}
int main() {
  rep2(i, 1, 100) {
    rep2(j, 1, 1000) {
      if (ss(j, i) < 1000)
        table[i][ss(j, i)] = j;
    }
  }
  while (1) {
    ans = 0;
    cin >> x >> y >> s;
    if (x == 0)
      break;
    rep2(i, 1, s) {
      ans = max(ans, ss(table[x][i], y) + ss(table[x][s - i], y));
    }
    cout << ans << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <queue>
#include <vector>

using namespace std;
#define rep2(x, from, to) for (int x = (from); (x) < (to); (x)++)
#define rep(x, to) rep2(x, 0, to)
#define INF 100000000
int x, y, s;
int ans;
int ss(int num, int tax) {
  int k = num * (100 + tax);
  return k / 100;
}
int main() {
  while (1) {
    ans = 0;
    cin >> x >> y >> s;
    rep2(i, 1, s) {
      rep2(j, 1, s) {
        if (ss(i, x) + ss(j, x) == s) {
          ans = max(ans, ss(i, y) + ss(j, y));
        }
      }
    }
    cout << ans << endl;
  }
}
Problem p00773 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>

using namespace std;

int main() {
  int x, y, s;

  while (cin >> x >> y >> s, x, y, s) {
    int m1 = 1;
    int m2 = s - 1;
    int ms1, ms2;
    int max = 0;
    int total = 0;

    while ((s / 2 + 1) != m1) {
      if ((m1 * 100) % (100 + x) == 0)
        ms1 = m1 * 100 / (100 + x);
      else
        ms1 = m1 * 100 / (100 + x) + 1;

      if ((m2 * 100) % (100 + x) == 0)
        ms2 = m2 * 100 / (100 + x);
      else
        ms2 = m2 * 100 / (100 + x) + 1;

      if ((ms1 * (100 + x) / 100 + ms2 * (100 + x) / 100) == s) {

        total = ms1 * (100 + y) / 100 + ms2 * (100 + y) / 100;

        if (max < total)
          max = total;
      }
      m1++;
      m2--;
    }
    cout << max << endl;
  }
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>

using namespace std;

int main() {
  int x, y, s;

  while (cin >> x >> y >> s, x, y, s) {
    int m1 = 1;
    int m2 = s - 1;
    int ms1, ms2;
    int max = 0;
    int total = 0;

    while ((s / 2 + 1) != m1) {
      if ((m1 * 100) % (100 + x) == 0)
        ms1 = m1 * 100 / (100 + x);
      else
        ms1 = m1 * 100 / (100 + x) + 1;

      if ((m2 * 100) % (100 + x) == 0)
        ms2 = m2 * 100 / (100 + x);
      else
        ms2 = m2 * 100 / (100 + x) + 1;

      if ((ms1 * (100 + x) / 100 + ms2 * (100 + x) / 100) == s) {

        total = ms1 * (100 + y) / 100 + ms2 * (100 + y) / 100;

        if (max < total)
          max = total;
        m1++;
        m2--;
      }
      cout << max << endl;
    }
  }
}
Problem p00773 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  while (true) {
    int x, y, s;
    cin >> x >> y >> s;

    if (x == 0 && y == 0 && s == 0)
      break;

    int tmax = -1;

    for (int a = 1; a <= s - 1; a++) {
      int ax = a * (100 + x) / 100;
      int ay = a * (100 + y) / 100;

      for (int b = 1; b <= s - 1; b++) {
        int bx = b * (100 + x) / 100;
        int by = b * (100 + y) / 100;

        if (ax + bx == s) {
          tmax = max(tmax, ay + by);
        } else if (ax + bx > s) {
          break;
        }
      }
    }
    cout << tmax << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  while (true) {
    int x, y, s;
    cin >> x >> y >> s;

    int tmax = -1;

    for (int a = 0; a < s - 1; a++) {
      int ax = a * (100 + x) / 50;
      int ay = a * (100 + y) / 50;

      for (int b = 1; b < s - 1; b++) {
        int bx = b * (100 + x) / 100;
        int by = b * (100 + y) / 100;

        if (ax + bx == s) {
          tmax = max(tmax, ay + by);
        } else if (ax + bx > s) {
          break;
        }
      }
    }
    cout << tmax << endl;
  }
  return 0;
}
Problem p00773 (C++) — buggy submission, verdict: Runtime Error

// 1192_TaxRateChanged.cpp
// 税率がx%の価格でループを回すのではなく、税抜き価格でループを回すのがポイント
#include <bits/stdc++.h>
using namespace std;
const int MAX_S = 1010;
int x, y, s;
int p[MAX_S];
void solve() {
  memset(p, 0, sizeof(p));
  for (int i = 1; i < s; ++i)
    for (int j = 1; j < s; ++j)
      if (i * (100 + x) / 100 + j * (100 + x) / 100 == s)
        p[i] = i * (100 + y) / 100 + j * (100 + y) / 100;

  cout << *max_element(p, p + s) << endl;
}
int main() {
  while (cin >> x >> y >> s) {
    if (x == 0 && y == 0 && s == 0)
      break;
    solve();
  }
  return 0;
}


Error: -11

Fixed submission:

// 1192_TaxRateChanged.cpp
// 税率がx%の価格でループを回すのではなく、税抜き価格でループを回すのがポイント
#include <bits/stdc++.h>
using namespace std;
const int MAX_S = 1010;
int x, y, s;
int p[MAX_S / 2];
void solve() {
  memset(p, 0, sizeof(p));
  for (int i = 1; i < s; ++i)
    for (int j = 1; j < s; ++j)
      if (i * (100 + x) / 100 + j * (100 + x) / 100 == s)
        p[i] = i * (100 + y) / 100 + j * (100 + y) / 100;

  cout << *max_element(p, p + s) << endl;
}
int main() {
  while (cin >> x >> y >> s) {
    if (x == 0 && y == 0 && s == 0)
      break;
    solve();
  }
  return 0;
}
Problem p00773 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;
using i64 = long long int;
using ui64 = unsigned long long int;

//////

int intax(int i, int p) { return floor((double)i * (100 + p) / 100); }

int main() {
  int x, y, s;
  while (cin >> x >> y >> s, x && y && s) {
    int res = -1;
    int mi, mj = 0;
    for (int i = 1; i < s; i++) {
      int xi = intax(i, x);
      if (xi > s)
        break;
      int j = 1;
      while (intax(j, x) + xi < s)
        j++;
      while (true) {
        int xj = intax(j, x);
        if (xi + xj > s)
          break;
        int yi = intax(i, y);
        int yj = intax(j, y);
        if (res < yi + yj) {
          mi = i, mj = j;
        }
        // cerr << i << " " << j << " " << yi + yj << endl;
        res = max(yi + yj, res);
        j++;
      }
    }
    // cerr << mi << " " << mj << endl;
    cout << res << endl;
  }
}


Error: 0
13 88
12 87
1 23
1 12
1 23
1 22
1 199
25 75
25 25
11 50
50 75
92 899
1 502
5 500
1 10
1 6


Fixed submission:

#include <bits/stdc++.h>

using namespace std;
using i64 = long long int;
using ui64 = unsigned long long int;

//////

int intax(int i, int p) { return floor((double)i * (100 + p) / 100); }

int main() {
  int x, y, s;
  while (cin >> x >> y >> s, x && y && s) {
    int res = -1;
    int mi, mj = 0;
    for (int i = 1; i < s; i++) {
      int xi = intax(i, x);
      if (xi > s)
        break;
      int j = 1;
      while (intax(j, x) + xi < s)
        j++;
      while (true) {
        int xj = intax(j, x);
        if (xi + xj > s)
          break;
        int yi = intax(i, y);
        int yj = intax(j, y);
        if (res < yi + yj) {
          mi = i, mj = j;
        }
        // cerr << i << " " << j << " " << yi + yj << endl;
        res = max(yi + yj, res);
        j++;
      }
    }
    cerr << mi << " " << mj << endl;
    cout << res << endl;
  }
}
Problem p00774 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define _                                                                      \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);
#define REP(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;

int board[10][5];

int main() {
  _;
  int h;
  while (cin >> h, h != 0) {
    REP(i, 10) REP(j, 5) board[i][j] = 0;
    REP(i, h) {
      REP(j, 5) { cin >> board[h - i - 1][j]; }
    }
    int sum = 0;
    bool chain = false;
    do {
      chain = false;
      REP(i, h) {
        REP(j, 3) {
          if (board[i][j] == 0)
            continue;
          int k = j + 1;
          for (; k < 5; k++) {
            if (board[i][j] != board[i][k])
              break;
          }
          if (k - j >= 3) {
            sum += board[i][j] * (k - j);
            for (; j < k; j++)
              board[i][j] = 0;
            break;
          }
        }
      }
      REP(j, 5) {
        REP(i, h - 1) {
          if (board[i][j] == 0) {
            int k = i + 1;
            for (; k < 10; k++) {
              if (board[k][j] != 0) {
                board[i][j] = board[k][j];
                board[k][j] = 0;
                chain = true;
                break;
              }
            }
          }
        }
      }
      // REP(i,10){
      // 	REP(j,5)
      // 	  cout<<board[i][j]<<" ";
      // 	cout<<endl;
      // }
      // cout<<endl;
    } while (chain);
    cout << sum << endl;
  }
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
#define _                                                                      \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);
#define REP(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;

int board[10][5];

int main() {
  _;
  int h;
  while (cin >> h, h != 0) {
    REP(i, 10) REP(j, 5) board[i][j] = 0;
    REP(i, h) {
      REP(j, 5) { cin >> board[h - i - 1][j]; }
    }
    int sum = 0;
    bool chain = false;
    do {
      chain = false;
      REP(i, h) {
        REP(j, 3) {
          if (board[i][j] == 0)
            continue;
          int k = j + 1;
          for (; k < 5; k++) {
            if (board[i][j] != board[i][k])
              break;
          }
          if (k - j >= 3) {
            sum += board[i][j] * (k - j);
            for (; j < k; j++)
              board[i][j] = 0;
            break;
          }
        }
      }
      REP(j, 5) {
        REP(i, h - 1) {
          if (board[i][j] == 0) {
            int k = i + 1;
            for (; board[k][j] == 0; k++) {
            }
            swap(board[i][j], board[k][j]);
            chain = true;
          }
        }
      }
    } while (chain);
    cout << sum << endl;
  }
}
Problem p00774 (C++) — buggy submission, verdict: Time Limit Exceeded

#include "bits/stdc++.h"
using namespace std;
#define int long long
#define REP(i, s, n) for (signed i = (s); i < signed(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(c) (c).begin(), (c).end()

using VV = vector<vector<int>>;
using V = vector<int>;
using P = pair<int, int>;
using IP = pair<int, P>;

const double EPS = 1e-9;

signed main() {
  int h;
  while (cin >> h && h) {
    VV board(h, V(5));
    rep(i, h) rep(j, 5) cin >> board[i][j];
    int score = 0;

    while (true) {
      int added = 0;
      VV next = board;
      rep(i, h) rep(j, 3) {
        if (board[i][j] == board[i][j + 1] && board[i][j] == board[i][j + 2]) {
          added += next[i][j] + next[i][j + 1] + next[i][j + 2];
          next[i][j] = next[i][j + 1] = next[i][j + 2] = 0;
        }
      }
      score += added;
      board = next;

      rep(j, 5) {
        int shift = 0;
        for (int i = h - 1; i >= 0; i--) {
          int tmp = board[i][j];
          board[i][j] = 0;
          board[i + shift][j] = tmp;
          shift += tmp == 0;
        }
      }

      if (added == 0)
        break;
    }

    cout << score << endl;
  }
}

Error: TLE

Fixed submission:

#include "bits/stdc++.h"
using namespace std;
#define int long long
#define REP(i, s, n) for (signed i = (s); i < signed(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(c) (c).begin(), (c).end()

using VV = vector<vector<int>>;
using V = vector<int>;
using P = pair<int, int>;
using IP = pair<int, P>;

const double EPS = 1e-9;

template <typename Func> double search(double left, double right, Func f) {
  for (int loop = 0; loop < 100000; ++loop) {
    if (f((left * 2 + right) / 3) < f((left + right * 2) / 3)) {
      right = (left + right * 2) / 3;
    } else {
      left = (left * 2 + right) / 3;
    }
  }
  return (right + left) * 0.5;
}

signed main() {
  int h;
  while (cin >> h && h) {
    VV board(h, V(5));
    rep(i, h) rep(j, 5) cin >> board[i][j];
    int score = 0;

    while (true) {
      int added = 0;
      VV next = board;
      rep(i, h) rep(j, 3) {
        if (board[i][j] == board[i][j + 1] && board[i][j] == board[i][j + 2]) {
          added += next[i][j] + next[i][j + 1] + next[i][j + 2];
          next[i][j] = next[i][j + 1] = next[i][j + 2] = 0;
        }
      }
      score += added;
      board = move(next);
      if (added != 0)
        break;
    }

    cout << score << endl;
  }
}
Problem p00774 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;
#define REP(i, n) for (int i = 0; i < n; ++i)

int tile[11][5];

int main() {
  int h;

  while (cin >> h, h) {
    REP(i, 11) REP(j, 5) { tile[i][j] = -1; }
    REP(i, h) REP(j, 5) { cin >> tile[h - 1 - i][j]; }
    int ans = 0;
    bool update = false;
    while (true) {
      update = false;
      REP(it, 11) {
        bool t1 = tile[it][0] == tile[it][1] && tile[it][0] != -1;
        bool t2 = tile[it][1] == tile[it][2] && tile[it][1] != -1;
        bool t3 = tile[it][2] == tile[it][3] && tile[it][2] != -1;
        bool t4 = tile[it][3] == tile[it][4] && tile[it][3] != -1;
        bool y1 = t1 && t2;
        bool y2 = t2 && t3;
        bool y3 = t3 && t4;
        if (y1 && y2 && y3) {
          ans += tile[it][0] * 5;
          REP(i, 5) { tile[it][i] = -1; }
          update = true;
        } else if (y1 && y2 || y2 && y3) {
          ans += tile[it][y3] * 4;
          REP(i, 4) { tile[it][i + y3] = -1; }
          update = true;
        } else if (y1 || y2 || y3) {
          ans += tile[it][2] * 3;
          REP(i, 3) { tile[it][i + y2 + ((int)y3) * 2] = -1; }
          update = true;
        }
      }
      REP(it, 10) {
        REP(i, 5) {
          if (tile[it][i] == -1) {
            int itt = it;
            while (tile[++itt][i] == -1 && itt != 10)
              ;
            swap(tile[it][i], tile[itt][i]);
          }
        }
      }
      if (!update)
        break;
    }
    cout << ans << endl;
  }
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
#define REP(i, n) for (int i = 0; i < n; ++i)

int tile[11][5];

int main() {
  int h;

  while (cin >> h, h) {
    REP(i, 11) REP(j, 5) { tile[i][j] = -1; }
    REP(i, h) REP(j, 5) { cin >> tile[h - 1 - i][j]; }
    int ans = 0;
    bool update = false;
    while (true) {
      update = false;
      REP(it, 11) {
        bool t1 = tile[it][0] == tile[it][1] && tile[it][0] != -1;
        bool t2 = tile[it][1] == tile[it][2] && tile[it][1] != -1;
        bool t3 = tile[it][2] == tile[it][3] && tile[it][2] != -1;
        bool t4 = tile[it][3] == tile[it][4] && tile[it][3] != -1;
        bool y1 = t1 && t2;
        bool y2 = t2 && t3;
        bool y3 = t3 && t4;
        if (y1 && y2 && y3) {
          ans += tile[it][0] * 5;
          REP(i, 5) { tile[it][i] = -1; }
          update = true;
        } else if (y1 && y2 || y2 && y3) {
          ans += tile[it][y3] * 4;
          REP(i, 4) { tile[it][i + y3] = -1; }
          update = true;
        } else if (y1 || y2 || y3) {
          ans += tile[it][2] * 3;
          REP(i, 3) { tile[it][i + y2 + ((int)y3) * 2] = -1; }
          update = true;
        }
      }
      REP(it, 11) {
        REP(i, 5) {
          if (tile[it][i] == -1) {
            int itt = it;
            while (tile[++itt][i] == -1 && itt != 10)
              ;
            swap(tile[it][i], tile[itt][i]);
          }
        }
      }
      if (!update)
        break;
    }
    cout << ans << endl;
  }
}
Problem p00774 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>

#pragma warning(disable : 4996)

using namespace std;

int main() {
  int H;

  while (true) {
    scanf("%d", &H);

    if (H == 0) {
      break;
    }

    vector<vector<int>> M(H, vector<int>(5));

    for (int i = 0; i < H; i++) {
      for (int j = 0; j < 5; j++) {
        scanf("%d", &M[i][j]);
      }
    }

    int ret = 0;

    while (true) {
      for (int i = 0; i < H; i++) {
        for (int j = 5; j >= 3; j--) {
          for (int k = 0; k <= 5 - j; k++) {
            bool ok = (M[i][k] != 0);

            for (int l = k + 1; l < k + j; l++) {
              if (M[i][l - 1] != M[i][l] || M[i][l] == 0) {
                ok = false;
              }
            }

            if (ok) {
              ret += M[i][k] * j;

              for (int l = k; l < k + j; l++) {
                M[i][l] = 0;
              }
            }
          }
        }
      }

      bool ok = false;

      for (int rep = 0; rep < H; rep++) {
        for (int i = H - 1; i >= 1; i--) {
          for (int j = 0; j < 5; j++) {
            if (M[i][j] == 0 && M[i - 1][j] != 0) {
              M[i][j] = M[i - 1][j];
              M[i - 1][j] = 0;
              ok = true;
            }
          }
        }
      }

      if (!ok) {
        break;
      }
    }

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

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>

#pragma warning(disable : 4996)

using namespace std;

int main() {
  int H;

  while (true) {
    scanf("%d", &H);

    if (H == 0) {
      break;
    }

    vector<vector<int>> M(H, vector<int>(5));

    for (int i = 0; i < H; i++) {
      for (int j = 0; j < 5; j++) {
        scanf("%d", &M[i][j]);
      }
    }

    int ret = 0;

    while (true) {
      for (int i = 0; i < H; i++) {
        for (int j = 5; j >= 3; j--) {
          for (int k = 0; k <= 5 - j; k++) {
            bool ok = (M[i][k] != 0);

            for (int l = k + 1; l < k + j; l++) {
              if (M[i][l - 1] != M[i][l] || M[i][l] == 0) {
                ok = false;
              }
            }

            if (ok) {
              ret += M[i][k] * j;

              for (int l = k; l < k + j; l++) {
                M[i][l] = 0;
              }
            }
          }
        }
      }

      bool ok = false;

      for (int i = H - 1; i >= 1; i--) {
        for (int j = 0; j < 5; j++) {
          if (M[i][j] == 0) {
            M[i][j] = M[i - 1][j];
            M[i - 1][j] = 0;
            ok = true;
          }
        }
      }

      if (!ok) {
        break;
      }
    }

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

  return 0;
}
Problem p00774 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
// void pfield(vector<vector<int> >, int);

int main() {
  int cols;
  while (cin >> cols, cols) {
    vector<vector<int>> field(5, vector<int>()); // [col][line]
    for (int il = 0; il < cols; ++il) {
      for (int ic = 0; ic < 5; ++ic) {
        int num;
        cin >> num;
        field[ic].push_back(num);
      }
    }
    for (int ic = 0; ic < 5; ++ic) {
      reverse(field[ic].begin(), field[ic].end());
    }
    int score = 0;
    int lastScore = 0;
    do {
      lastScore = score;
      // Top down scan
      for (int il = cols; il >= 0; --il) {
        int rowCnt = 0;
        int lastNum = -1;
        for (int ic = 0; ic < 5; ++ic) {
          if (field[ic].size() <= il) {
            rowCnt = 0;
            lastNum = -1;
            continue;
          }
          (field[ic][il] == lastNum) ? ++rowCnt : (rowCnt = 0);
          int eraseNum = lastNum;
          lastNum = field[ic][il];
          if (rowCnt == 2) {
            for (int dic = -2; dic <= 0; ++dic) {
              field[ic + dic].erase(field[ic + dic].begin() + il);
              score += eraseNum;
            }
          } else if (rowCnt > 2) {
            field[ic].erase(field[ic].begin() + il);
            score += eraseNum;
          }
        }
        // pfield(field, cols);
      }
    } while (score != lastScore);
    cout << score << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
// void pfield(vector<vector<int> >, int);

int main() {
  int cols;
  while (cin >> cols, cols) {
    vector<vector<int>> field(5, vector<int>()); // [col][line]
    for (int il = 0; il < cols; ++il) {
      for (int ic = 0; ic < 5; ++ic) {
        int num;
        cin >> num;
        field[ic].push_back(num);
      }
    }
    for (int ic = 0; ic < 5; ++ic) {
      reverse(field[ic].begin(), field[ic].end());
    }
    int score = 0;
    int lastScore = 0;
    do {
      lastScore = score;
      // Top down scan
      for (int il = cols; il >= 0; --il) {
        int rowCnt = 0;
        int lastNum = -1;
        for (int ic = 0; ic < 5; ++ic) {
          if (field[ic].size() <= il) {
            rowCnt = 0;
            continue;
          }
          (field[ic][il] == lastNum) ? ++rowCnt : (rowCnt = 0);
          int eraseNum = lastNum;
          lastNum = field[ic][il];
          if (rowCnt == 2) {
            for (int dic = -2; dic <= 0; ++dic) {
              field[ic + dic].erase(field[ic + dic].begin() + il);
              score += eraseNum;
            }
          } else if (rowCnt > 2) {
            field[ic].erase(field[ic].begin() + il);
            score += eraseNum;
          }
        }
      }
    } while (score != lastScore);
    cout << score << endl;
  }
  return 0;
}