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

#include <bits/stdc++.h>
#define MAXN 13
#define MAXM 550005
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int n;
string str;
int ans[MAXM];
int curdigit[MAXN], curres[MAXN];
string reduce(string &t) {
  vector<char> st;
  string ret = "";
  for (auto ch : t) {
    st.push_back(ch);
    if (st.size() >= 2 && st[(int)st.size() - 1] == 'S' &&
        st[(int)st.size() - 2] == 'S')
      st.pop_back(), st.pop_back();
  }
  for (auto ch : st)
    ret += ch;
  return ret;
}
void update_ans() {
  int x = 0, y = 0;
  for (int i = n - 1; i >= 0; i--) {
    x = x * 3 + curdigit[i];
    y = y * 3 + curres[i];
  }
  ans[x] = y;
}
void solve(int cur, string t) {
  if (cur == n) {
    update_ans();
    return;
  }
  for (int d = 0; d < 3; d++) {
    string curt = "";
    int curd = d;
    for (auto ch : t) {
      if (ch == 'S') {
        if (curd)
          curd = 3 - curd;
        curt += 'S';
      }
      if (ch == 'R') {
        curd++;
        if (curd == 3) {
          curd = 0;
          curt += 'R';
        }
      }
    }
    curdigit[cur] = d;
    curres[cur] = curd;
    solve(cur + 1, reduce(curt));
  }
}
int main() {
  scanf("%d", &n);
  cin >> str;
  solve(0, reduce(str));
  int p = 1;
  for (int i = 0; i < n; i++)
    p = p * 3;
  for (int i = 0; i < p; i++)
    printf("%d ", ans[i]);
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define MAXN 13
#define MAXM 500005
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int n;
string str;
int ans[MAXM];
int curdigit[MAXN], curres[MAXN];
string reduce(string &t) {
  vector<char> st;
  string ret = "";
  for (auto ch : t) {
    st.push_back(ch);
    if (st.size() >= 2 && st[(int)st.size() - 1] == 'S' &&
        st[(int)st.size() - 2] == 'S')
      st.pop_back(), st.pop_back();
  }
  for (auto ch : st)
    ret += ch;
  return ret;
}
void update_ans() {
  int x = 0, y = 0;
  for (int i = n - 1; i >= 0; i--) {
    x = x * 3 + curdigit[i];
    y = y * 3 + curres[i];
  }
  ans[x] = y;
}
void solve(int cur, string t) {
  if (cur == n) {
    update_ans();
    return;
  }
  for (int d = 0; d < 3; d++) {
    string curt = "";
    int curd = d;
    for (auto ch : t) {
      if (ch == 'S') {
        if (curd)
          curd = 3 - curd;
        curt += 'S';
      }
      if (ch == 'R') {
        curd++;
        if (curd == 3) {
          curd = 0;
          curt += 'R';
        }
      }
    }
    curdigit[cur] = d;
    curres[cur] = curd;
    solve(cur + 1, reduce(curt));
  }
}
int main() {
  scanf("%d", &n);
  cin >> str;
  solve(0, reduce(str));
  int p = 1;
  for (int i = 0; i < n; i++)
    p = p * 3;
  for (int i = 0; i < p; i++)
    printf("%d ", ans[i]);
  return 0;
}
Problem p02671 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
using namespace std;
const int N = 1800005;
int n, rt, cnt, ind, pw[N], ch[N][3], tg[N], val[N], ans[N];
char s[N];
void bud(int &k1, int k2, int k3) {
  k1 = ++cnt;
  if (k2 == n) {
    val[k1] = k3;
    return;
  }
  rep(i, 0, 2) bud(ch[k1][i], k2 + 1, k3 + pw[k2] * i);
}
void pst(int k1) {
  if (!ch[k1][0])
    return;
  swap(ch[k1][1], ch[k1][2]);
  tg[k1] ^= 1;
}
void psd(int k1) {
  if (!ch[k1][0])
    return;
  if (tg[k1]) {
    pst(ch[k1][0]);
    pst(ch[k1][1]);
    pst(ch[k1][2]);
    tg[k1] ^= 1;
  }
}
void go(int k1) {
  if (!ch[k1][0])
    return;
  psd(k1);
  int t = ch[k1][2];
  ch[k1][2] = ch[k1][1], ch[k1][1] = ch[k1][0], ch[k1][0] = t;
  go(ch[k1][0]);
}
void dfs(int k1, int k2, int k3) {
  if (k2 == n) {
    ans[val[k1]] = k3;
    return;
  }
  psd(k1);
  rep(i, 0, 2) dfs(ch[k1][i], k2 + 1, k3 + pw[k2] * i);
}
int main() {
  scanf("%d%s", &n, s);
  pw[0] = 1;
  rep(i, 1, n) pw[i] = pw[i - 1] * 3;
  bud(rt, 0, 0);
  for (int i = 0; s[i]; ++i) {
    if (s[i] == 'S')
      pst(rt);
    else
      go(rt);
  }
  dfs(rt, 0, 0);
  rep(i, 0, pw[n] - 1) printf("%d ", ans[i]);
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
using namespace std;
const int N = 600005;
int n, rt, cnt, ind, pw[N], ch[N][3], tg[N], val[N], ans[N];
char s[N];
void bud(int &k1, int k2, int k3) {
  k1 = ++cnt;
  if (k2 == n) {
    val[k1] = k3;
    return;
  }
  rep(i, 0, 2) bud(ch[k1][i], k2 + 1, k3 + pw[k2] * i);
}
void pst(int k1) {
  if (!ch[k1][0])
    return;
  swap(ch[k1][1], ch[k1][2]);
  tg[k1] ^= 1;
}
void psd(int k1) {
  if (!ch[k1][0])
    return;
  if (tg[k1]) {
    pst(ch[k1][0]);
    pst(ch[k1][1]);
    pst(ch[k1][2]);
    tg[k1] ^= 1;
  }
}
void go(int k1) {
  if (!ch[k1][0])
    return;
  psd(k1);
  int t = ch[k1][2];
  ch[k1][2] = ch[k1][1], ch[k1][1] = ch[k1][0], ch[k1][0] = t;
  go(ch[k1][0]);
}
void dfs(int k1, int k2, int k3) {
  if (k2 == n) {
    ans[val[k1]] = k3;
    return;
  }
  psd(k1);
  rep(i, 0, 2) dfs(ch[k1][i], k2 + 1, k3 + pw[k2] * i);
}
int main() {
  scanf("%d%s", &n, s);
  pw[0] = 1;
  rep(i, 1, n) pw[i] = pw[i - 1] * 3;
  bud(rt, 0, 0);
  for (int i = 0; s[i]; ++i) {
    if (s[i] == 'S')
      pst(rt);
    else
      go(rt);
  }
  dfs(rt, 0, 0);
  rep(i, 0, pw[n] - 1) printf("%d ", ans[i]);
  return 0;
}
Problem p02671 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define LL long long
#define SZ(x) (int)x.size() - 1
#define F(i, a, b) for (int i = a; i <= b; ++i)
#define DF(i, a, b) for (int i = a; i >= b; --i)
#define pb push_back
#define ms(a, b) memset(a, b, sizeof a)
using namespace std;
int read() {
  char ch = getchar();
  int w = 1, c = 0;
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-')
      w = -1;
  for (; isdigit(ch); ch = getchar())
    c = (c << 3) + (c << 1) + (ch ^ 48);
  return w * c;
}
const int M = 5e6 + 10;
int t[M][3], n, pw[M];
int val[M], rt, tot, ans[M];
bool tg[M];
char ch[M];
void rev(int x) {
  tg[x] ^= 1;
  swap(t[x][1], t[x][2]);
}
void pd(int x) {
  if (tg[x]) {
    F(i, 0, 2)
    rev(t[x][i]);
    tg[x] = 0;
  }
}
void build(int &x, int dep, int o) {
  x = ++tot;
  val[x] = o;
  if (dep == n)
    return;
  F(i, 0, 2) build(t[x][i], dep + 1, o + pw[dep] * i);
}
void add(int x, int dep) {
  if (dep == n)
    return;
  pd(x);
  int t0 = t[x][0], t1 = t[x][1], t2 = t[x][2];
  t[x][0] = t2;
  t[x][1] = t0;
  t[x][2] = t1;
  add(t[x][0], dep + 1);
}
void calc(int x, int dep, int o) {
  if (dep == n) {
    ans[val[x]] = o;
    return;
  }
  pd(x);
  F(i, 0, 2) calc(t[x][i], dep + 1, o + pw[dep] * i);
}
int main() {
  n = read();
  scanf("%s", ch + 1);
  int m = strlen(ch + 1);
  pw[0] = 1;
  F(i, 1, 20) pw[i] = pw[i - 1] * 3;
  build(rt, 0, 0);
  F(i, 1, m) {
    if (ch[i] == 'S')
      rev(rt);
    else
      add(rt, 0);
  }
  calc(1, 0, 0);

  F(i, 0, pw[n] - 1) { cout << ans[i] << " "; }
  cout << "\\n";
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define LL long long
#define SZ(x) (int)x.size() - 1
#define F(i, a, b) for (int i = a; i <= b; ++i)
#define DF(i, a, b) for (int i = a; i >= b; --i)
#define pb push_back
#define ms(a, b) memset(a, b, sizeof a)
using namespace std;
int read() {
  char ch = getchar();
  int w = 1, c = 0;
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-')
      w = -1;
  for (; isdigit(ch); ch = getchar())
    c = (c << 3) + (c << 1) + (ch ^ 48);
  return w * c;
}
const int M = 6e5 + 10;
int t[M][3], n, pw[M];
int val[M], rt, tot, ans[M];
bool tg[M];
char ch[M];
void rev(int x) {
  tg[x] ^= 1;
  swap(t[x][1], t[x][2]);
}
void pd(int x) {
  if (tg[x]) {
    F(i, 0, 2)
    rev(t[x][i]);
    tg[x] = 0;
  }
}
void build(int &x, int dep, int o) {
  x = ++tot;
  val[x] = o;
  if (dep == n)
    return;
  F(i, 0, 2) build(t[x][i], dep + 1, o + pw[dep] * i);
}
void add(int x, int dep) {
  if (dep == n)
    return;
  pd(x);
  int t0 = t[x][0], t1 = t[x][1], t2 = t[x][2];
  t[x][0] = t2;
  t[x][1] = t0;
  t[x][2] = t1;
  add(t[x][0], dep + 1);
}
void calc(int x, int dep, int o) {
  if (dep == n) {
    ans[val[x]] = o;
    return;
  }
  pd(x);
  F(i, 0, 2) calc(t[x][i], dep + 1, o + pw[dep] * i);
}
int main() {
  n = read();
  scanf("%s", ch + 1);
  int m = strlen(ch + 1);
  pw[0] = 1;
  F(i, 1, 20) pw[i] = pw[i - 1] * 3;
  build(rt, 0, 0);
  F(i, 1, m) {
    if (ch[i] == 'S')
      rev(rt);
    else
      add(rt, 0);
  }
  calc(1, 0, 0);

  F(i, 0, pw[n] - 1) { cout << ans[i] << " "; }
  cout << "\\n";
  return 0;
}
Problem p02673 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef double DB;
const int maxn = (int)2e5 + 1;
struct Point {
  LL x, y;
  bool operator<(Point const &t) const {
    return x != t.x ? (x < t.x) : (y < t.y);
  }
  Point operator-(Point const &t) const { return (Point){x - t.x, y - t.y}; }
  LL det(Point const &t) const { return x * t.y - y * t.x; }
} p[maxn];
int n, b[maxn], m, stk[maxn];
LL a[maxn], c[maxn];
int main() {
  scanf("%d", &n);
  int pos = 0;
  for (int i = 0; i < n; ++i) {
    scanf("%lld", a + i);
    if (a[pos] < a[i])
      pos = i;
  }
  for (int i = 0; i < n; ++i)
    scanf("%d", b + i);
  rotate(a, a + pos, a + n);
  rotate(b, b + pos, b + n);
  a[n] = a[0];
  for (int i = 0; i <= n; ++i) {
    if (i > 1)
      c[i] = (b[i - 1] + c[i - 1]) * 2 - c[i - 2];
    p[i] = (Point){i, a[i] - c[i]};
    for (;
         m > 1 && (p[stk[m - 1]] - p[stk[m - 2]]).det(p[i] - p[stk[m - 1]]) > 0;
         --m)
      ;
    stk[m++] = i;
  }
  DB ans = 0;
  for (int i = 0, j = 0; i < n; ++i) {
    for (; stk[j] < i; ++j)
      ;
    if (stk[j] == i) {
      ans += a[i];
    } else {
      ans += ((i - stk[j - 1]) * p[stk[j]].y + (stk[j] - i) * p[stk[j - 1]].y) /
                 (DB)(stk[j] - stk[j - 1]) +
             c[i];
    }
  }
  printf("%.20f\\n", ans / n);
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef double DB;
const int maxn = (int)2e5 + 1;
int n, b[maxn], pL[maxn], pR[maxn];
DB dp[maxn];
bool vis[maxn];
priority_queue<pair<DB, int>> Q;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    LL x;
    scanf("%lld", &x);
    dp[i] = x;
    Q.push(make_pair(dp[i], i));
  }
  for (int i = 0; i < n; ++i) {
    scanf("%d", b + i);
    pL[i] = (i + n - 1) % n;
    pR[i] = (i + 1) % n;
  }
  while (!Q.empty()) {
    int u = Q.top().second;
    Q.pop();
    // if(vis[u])
    // 	continue;
    // vis[u] = 1;
    auto check = [&](int v) {
      DB tmp = (dp[pL[v]] + dp[pR[v]]) / 2 - b[v];
      if (tmp > dp[v]) {
        dp[v] = tmp;
        Q.push(make_pair(dp[v], v));
      }
    };
    check(pL[u]);
    check(pR[u]);
  }
  DB ans = 0;
  for (int i = 0; i < n; ++i)
    ans += dp[i];
  printf("%.20f\\n", ans / n);
  return 0;
}
Problem p02673 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
const int N = 2e5 + 5;

int n, top, stk[N];
double a[N], b[N], tmp[N];
double s[N], s2[N];

void move(double a[], int x) {
  rep(i, x, n) tmp[i - x + 1] = a[i];
  rep(i, 1, x - 1) tmp[i + n + 1 - x] = a[i];
  tmp[n + 1] = a[x];
  rep(i, 1, n + 1) a[i] = tmp[i];
}

double calc(int l, int r) {
  if (r <= l + 1)
    return a[r];
  double suma = (r - l - 1.0) / (r - l) * a[l] + 1.0 / (r - l) * a[r];
  double sumb = 2.0 * (s2[r - 1] - (s2[l] + (r - l - 1) * s[l])) / (r - l);
  return suma - sumb;
}

bool cmp(int l, int m, int r) { return calc(l, m) < calc(l, r); }

int main() {
  scanf("%d", &n);
  rep(i, 1, n) scanf("%lf", a + i);
  rep(i, 1, n) scanf("%lf", b + i);

  int maxi = max_element(a + 1, a + n + 1) - a;
  move(a, maxi);
  move(b, maxi);
  n++;

  rep(i, 1, n) s[i] = s[i - 1] + b[i];
  rep(i, 1, n) s2[i] = s2[i - 1] + s[i];

  stk[top = 1] = 1;
  rep(i, 2, n) {
    while (top > 1 && cmp(stk[top - 1], stk[top], i))
      --top;
    stk[++top] = i;
  }
  for (; top > 1; --top) {
    int l = stk[top - 1], r = stk[top];
    rep(i, l + 1, r - 1) a[i] = calc(i - 1, r);
  }

  n--;
  double ans = 0;
  rep(i, 1, n) ans += a[i];
  printf("%.10lf", ans / n);
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
const int N = 2e5 + 5;

int n;
double a[N], b[N];
bool v[N];

double move(int x) {
  int l = x == 1 ? n : x - 1, r = x == n ? 1 : x + 1;
  return (a[l] + a[r]) / 2 - b[x];
}

int main() {
  scanf("%d", &n);
  rep(i, 1, n) scanf("%lf", a + i);
  rep(i, 1, n) scanf("%lf", b + i);

  queue<int> Q;
  memset(v, 0, sizeof v);
  rep(i, 1, n) if (a[i] < move(i)) {
    a[i] = move(i);
    Q.push(i);
    v[i] = 1;
  }

  while (!Q.empty()) {
    int x = Q.front();
    Q.pop(), v[x] = false;
    int l = x == 1 ? n : x - 1, r = x == n ? 1 : x + 1;
    if (a[l] < move(l)) {
      a[l] = move(l);
      if (!v[l])
        Q.push(l), v[l] = true;
    }
    if (a[r] < move(r)) {
      a[r] = move(r);
      if (!v[r])
        Q.push(r), v[r] = true;
    }
  }

  double ans = 0;
  rep(i, 1, n) ans += a[i];
  ans /= n;
  printf("%.10lf", ans);
  return 0;
}
Problem p02673 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

int main() {
  using namespace std;

  unsigned long N;
  cin >> N;

  vector<unsigned long> A(N), B(N);
  for (auto &&i : A)
    cin >> i;
  for (auto &&i : B)
    cin >> i;
  unsigned long t{
      static_cast<unsigned long>(max_element(begin(A), end(A)) - begin(A))};
  rotate(begin(A), begin(A) + t, end(A));
  rotate(begin(B), begin(B) + t, end(B));
  A.push_back(A[0]);
  B.push_back(B[0]);

  vector<unsigned long> C(N + 1);
  C[0] = 10000000000000;
  C[1] = 10000000000000;

  for (unsigned long i{2}; i <= N; ++i)
    C[i] = 2 * C[i - 1] - 2 * B[i - 1] - C[i - 2];

  for (unsigned long i{0}; i <= N; ++i)
    A[i] += C[i] -= C.back();

  vector<unsigned long> convex_hull{0, 1};
  const auto &is_convex = [&A](unsigned long i, unsigned long j,
                               unsigned long k) -> bool {
    return j * A[k] + k * A[i] + i * A[j] < j * A[i] + k * A[j] + i * A[k];
  };
  for (unsigned long i{2}; i < N + 1; ++i) {
    while (convex_hull.size() >= 2 &&
           !is_convex(convex_hull.end()[-2], convex_hull.end()[-1], i))
      convex_hull.pop_back();
    convex_hull.push_back(i);
  }
  unsigned long ans{0};
  for (unsigned long i{0}; i + 1 < convex_hull.size(); ++i)
    ans += (convex_hull[i + 1] - convex_hull[i] + 1) * A[convex_hull[i]] +
           (convex_hull[i + 1] - convex_hull[i] - 1) * A[convex_hull[i + 1]];

  printf("%.12Lf\\n",
         (ans - 2 * accumulate(C.begin(), C.end(), 0UL)) / (2.0L * N));

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

int main() {
  using namespace std;
  unsigned long N;
  cin >> N;
  vector<long double> A(N), B(N);
  for (auto &&i : A)
    cin >> i;
  for (auto &&i : B)
    cin >> i;
  A.push_back(A[0]);
  B.push_back(B[0]);
  A.push_back(A[1]);
  B.push_back(B[1]);

  constexpr unsigned long mx{10000};
  for (unsigned long iter{0}; iter < mx; ++iter) {
    for (unsigned long i{1}; i <= N; ++i) {
      if (2 * (A[i] + B[i]) < A[i - 1] + A[i + 1]) {
        A[i] = (A[i - 1] + A[i + 1]) / 2 - B[i];
        if (i == 1)
          A[N + 1] = A[1];
        if (i == N)
          A[0] = A[N];
      }
    }
  }

  printf("%.12Lf\\n", accumulate(begin(A) + 2, end(A), 0.0L) / N);

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

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

typedef long long LL;

const int N = 100;
const int db[6][20] = {{},
                       {1, 2},
                       {0, 0, 2},
                       {0, 0, 0, 4, 6},
                       {0, 0, 0, 0, 36, 108, 220, 334, 384},
                       {0, 0, 0, 0, 0, 976, 1001, 1001, 1001, 1001, 1001, 1001,
                        1001, 1001, 1001, 1001, 1001}};

LL n;

void into() { scanf("%lld", &n); }

int dp[N + 9];

void Get_dp() {
  dp[1] = 0;
  for (int i = 2; i < N; ++i)
    for (int j = 1; 2333; ++j)
      if ((1LL << j) - i >= dp[j]) {
        dp[i] = j;
        break;
      }
}

int Get_dp(LL n) {
  if (n < N)
    return dp[n];
  for (int i = 1; 2333; ++i)
    if ((1LL << i) - n >= dp[i])
      return i;
  return -1;
}

int Dfs_ans(LL n, LL m) {
  if (n < m)
    swap(n, m);
  if (m < 63 && (1LL << m) - n < n)
    return Dfs_ans((1LL << m) - n, m);
  if (m > 5)
    return 1001;
  return m ? db[m][n] : 1;
}

int ans;

void Get_ans() {
  ans = Dfs_ans(n, (LL)Get_dp(n));
  ans += n == 4;
  ans += (n == 7) << 1;
}

void work() {
  Get_dp();
  Get_ans();
}

void outo() { printf("%d\\n", ans > 1000 ? -1 : ans); }

int main() {
  into();
  work();
  outo();
  return 0;
}

Error: TLE

Fixed submission:

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

typedef long long LL;
#define int LL

const int N = 100;
const int db[6][20] = {{},
                       {1, 2},
                       {0, 0, 2},
                       {0, 0, 0, 4, 6},
                       {0, 0, 0, 0, 36, 108, 220, 334, 384},
                       {0, 0, 0, 0, 0, 976, 1001, 1001, 1001, 1001, 1001, 1001,
                        1001, 1001, 1001, 1001, 1001}};

LL n;

void into() { scanf("%lld", &n); }

int dp[N + 9];

void Get_dp() {
  dp[1] = 0;
  for (int i = 2; i < N; ++i)
    for (int j = 1; 2333; ++j)
      if ((1LL << j) - i >= dp[j]) {
        dp[i] = j;
        break;
      }
}

int Get_dp(LL n) {
  if (n < N)
    return dp[n];
  for (int i = 1; 2333; ++i)
    if ((1LL << i) - n >= dp[i])
      return i;
  return -1;
}

int Dfs_ans(LL n, LL m) {
  if (n < m)
    swap(n, m);
  if (m < 63 && (1LL << m) - n < n)
    return Dfs_ans((1LL << m) - n, m);
  if (m > 5)
    return 1001;
  return m ? db[m][n] : 1;
}

int ans;

int Get_ans() {
  ans = Dfs_ans(n, (LL)Get_dp(n));
  ans += n == 4;
  ans += (n == 7) << 1;
}

void work() {
  Get_dp();
  Get_ans();
}

void outo() { printf("%lld\\n", ans > 1000 ? -1 : ans); }

#undef int

int main() {
  into();
  work();
  outo();
  return 0;
}
Problem p02674 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
typedef long long ll;
const int inf = 2333;
inline ll read() {
  ll x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-')
      f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = (x << 1) + (x << 3) + c - '0';
    c = getchar();
  }
  return x * f;
}
ll n;
int g[233];
void init() {
  g[1] = 0;
  for (int i = 2; i <= 80; ++i) {
    for (int k = 1;; ++k) {
      if ((1LL << k) - i >= g[k]) {
        g[i] = k;
        break;
      }
    }
  }
}
const int table[6][23] = {{},
                          {1, 2},
                          {0, 0, 2},
                          {0, 0, 0, 4, 6},
                          {0, 0, 0, 0, 36, 108, 220, 334, 384},
                          {0, 0, 0, 0, 0, 976, inf, inf, inf, inf, inf, inf,
                           inf, inf, inf, inf, inf}};
int Get_g(ll n) {
  if (n <= 80)
    return g[n];
  for (int k = 1;; ++k) {
    if ((1LL << k) - n >= g[k])
      return k;
  }
  return 114514;
}
int Solve(ll n, ll k) {
  if (n < k)
    swap(n, k);
  if (!k)
    return 1;
  if (k < 63 && (1LL << (k - 1)) < n) {
    return Solve((1LL << k) - n, k);
  }
  if (k <= 5)
    return table[k][n];
  return inf;
}
int main() {
  init();
  n = read();
  int ans = Solve(n, Get_g(n)) + (n == 4) + (n == 7) * 2;
  printf("%d\\n", ans > 1000 ? -1 : ans);
  return 0;
}


Error: TLE

Fixed submission:

#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
typedef long long ll;
const int inf = 2333;
inline ll read() {
  ll x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-')
      f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = (x << 1) + (x << 3) + c - '0';
    c = getchar();
  }
  return x * f;
}
ll n;
int g[233];
void init() {
  g[1] = 0;
  for (int i = 2; i <= 80; ++i) {
    for (int k = 1;; ++k) {
      if ((1LL << k) - i >= g[k]) {
        g[i] = k;
        break;
      }
    }
  }
}
const int table[6][23] = {{},
                          {1, 2},
                          {0, 0, 2},
                          {0, 0, 0, 4, 6},
                          {0, 0, 0, 0, 36, 108, 220, 334, 384},
                          {0, 0, 0, 0, 0, 976, inf, inf, inf, inf, inf, inf,
                           inf, inf, inf, inf, inf}};
int Get_g(ll n) {
  if (n <= 80)
    return g[n];
  for (int k = 1;; ++k) {
    if ((1LL << k) - n >= g[k])
      return k;
  }
  return 114514;
}
int Solve(ll n, ll k) {
  if (n < k)
    swap(n, k);
  if (k < 63 && (1LL << (k - 1)) < n) {
    return Solve((1LL << k) - n, k);
  }
  if (!k)
    return 1;
  if (k <= 5)
    return table[k][n];
  return inf;
}
int main() {
  init();
  n = read();
  int ans = Solve(n, Get_g(n)) + (n == 4) + (n == 7) * 2;
  printf("%d\\n", ans > 1000 ? -1 : ans);
  return 0;
}
Problem p02675 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n;
  cin >> n;
  vector<string> s(10);
  s[1] = "pon";
  s[2] = "hon";
  s[3] = "bon";
  s[4] = "hon";
  s[5] = "hon";
  s[6] = "pon";
  s[7] = "hon";
  s[8] = "pon";
  s[9] = "hon";
  s[0] = "pon";
  cout << s[n % 10] << endl;
  return 0;
}

Error: -6
terminate called after throwing an instance of 'std::out_of_range'
  what():  basic_string::at: __n (which is 3) >= this->size() (which is 2)


Fixed submission:

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

int main() {
  string n;
  cin >> n;
  if (n.at(3) == 3)
    n = "bon";
  if (n.at(3) == 0 || 1 || 6 || 8)
    n = "pon";
  if (n.at(3) == 2 || 4 || 5 || 7 || 9)
    n = "hon";
  cout << n << endl;
  return 0;
}
Problem p02675 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define multitest 0
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define pqgreater(x) x, vector<x>, greater<x>
const ll mod = 998244353;
int solve();
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t = 1;
  if (multitest)
    cin >> t;
  while (t--)
    solve();
  return 0;
}
int solve() {
  int n;
  cin >> n;
  if (n % 10 == 3)
    cout << "bon\\n";
  else if (n % 10 == 0 || n % 10 == 1 || n % 10 == 6 || n % 10 == 8)
    cout << "pon\\n";
  else
    cout << "hon\\n";
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define multitest 0
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define pqgreater(x) x, vector<x>, greater<x>
const ll mod = 998244353;
int solve();
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t = 1;
  if (multitest)
    cin >> t;
  while (t--)
    solve();
}
int solve() {
  int n;
  cin >> n;
  if (n % 10 == 3)
    cout << "bon\\n";
  else if (n % 10 == 0 || n % 10 == 1 || n % 10 == 6 || n % 10 == 8)
    cout << "pon\\n";
  else
    cout << "hon\\n";
}
Problem p02675 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  int a;
  cin >> a;
  while (a != 0 & a > 10) {
    a = a % 10;
  }

  if (a == 2 || a == 4 || a == 5 || a == 7 || a == 9)
    cout << "hon" << endl;
  else if (a == 0 || a == 1 || a == 6 || a == 8)
    cout << "pon" << endl;
  else if (a == 3)
    cout << "bon" << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int a;
  while (a >= 0 && a < 10) {
    a = a / 10;
  }
  if (a == 2 || a == 4 || a == 5 || a == 7 || a == 9)
    cout << "hon" << endl;
  else if (a == 0 || a == 1 || a == 6 || a == 8)
    cout << "pon" << endl;
  else if (a == 3)
    cout << "bon" << endl;
}