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

#include <atcoder/convolution>
#include <iostream>
#include <list>
#include <vector>
using namespace std;
using namespace atcoder;

long long powmod(long long a, long long b, long long m) {
  long long r = 1;
  for (; b > 0; b >>= 1, a = a * a % m)
    if (b & 1)
      r = r * a % m;
  return r;
}

int main() {
  int N;
  cin >> N;
  vector<int> h(2 * N);
  for (int &a : h) {
    cin >> a;
    a--;
  }

  vector<int> C(100000);
  for (int a : h)
    C[a]++;

  long long M = 998244353;
  vector<long long> F(2 * N + 1);
  F[0] = 1;
  for (int i = 1; i <= 2 * N; i++)
    F[i] = F[i - 1] * i % M;

  vector<long long> FF(2 * N + 1);
  FF[0] = FF[1] = 1;
  for (int i = 2; i <= 2 * N; i++)
    FF[i] = FF[i - 2] * i % M;

  list<vector<long long>> T;
  for (int c : C)
    if (c > 0) {
      vector<long long> A(c / 2 + 1);
      for (int i = 0; i * 2 <= c; i++)
        A[i] = F[c] * powmod(F[i * 2], M - 2, M) % M *
               powmod(F[c - i * 2], M - 2, M) % M *
               (i == 0 ? 1 : FF[2 * i - 1]) % M;
      T.push_back(A);
    }

  while (T.size() > 1) {
    vector<long long> A = T.front();
    T.pop_front();
    vector<long long> B = T.front();
    T.pop_front();
    vector<long long> C = convolution(A, B);
    T.push_back(C);
  }

  vector<long long> A = T.front();
  for (int i = 0; i < (int)A.size(); i++)
    A[i] = A[i] * (N * 2 - 2 * i - 1 >= 0 ? FF[N * 2 - 2 * i - 1] : 1) % M;

  long long ans = 0;
  for (int i = 0; i < (int)A.size(); i++)
    ans = (ans + A[i] * (1 - 2 * (i & 1)) + M) % M;
  cout << ans << endl;
}


Error: TLE

Fixed submission:

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

long long powmod(long long a, long long b, long long m) {
  long long r = 1;
  for (; b > 0; b >>= 1, a = a * a % m)
    if (b & 1)
      r = r * a % m;
  return r;
}

int main() {
  int N;
  cin >> N;
  vector<int> h(2 * N);
  for (int &a : h) {
    cin >> a;
    a--;
  }

  vector<int> C(100000);
  for (int a : h)
    C[a]++;

  long long M = 998244353;
  vector<long long> F(2 * N + 1);
  F[0] = 1;
  for (int i = 1; i <= 2 * N; i++)
    F[i] = F[i - 1] * i % M;

  vector<long long> T(N + 1);
  T[0] = 1;
  for (int h = 0; h < 100000; h++) {
    vector<long long> P = T;

    int c = C[h];
    for (int i = 1; i * 2 <= c; i++) {
      long long p = F[c] * powmod(F[i * 2], M - 2, M) % M *
                    powmod(F[c - i * 2], M - 2, M) % M;
      for (int j = 0; j < i; j++)
        p = p * (2 * i - 2 * j - 1) % M;
      for (int j = 0; j + i <= N; j++)
        (T[j + i] += P[j] * p) %= M;
    }
  }

  long long p = 1;
  for (int i = 1; i <= N; i++) {
    p = p * (2 * i - 1) % M;
    (T[N - i] *= p) %= M;
  }

  // for (long long t: T)
  //     cout<<" "<<t;
  // cout<<endl;

  long long ans = 0;
  for (int i = 0; i <= N; i++)
    ans = (ans + T[i] * (1 - 2 * (i & 1))) % M;
  cout << ans << endl;
}
Problem p02541 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
using namespace std;
typedef long double DB;
typedef long long LL;

LL n, ans;

inline LL Mul(LL x, LL y, LL MOD) {
  return (x * y + MOD - (LL)((DB)x / MOD * y) * MOD) % MOD;
}
LL exgcd(LL a, LL b, LL &x, LL &y) {
  if (!b) {
    x = 1;
    y = 0;
    return a;
  }
  LL r = exgcd(b, a % b, y, x);
  y -= a / b * x;
  return r;
}
LL Solve(LL A, LL B, LL C) {
  LL x, y, r = exgcd(A, B, x, y);
  if (C % r)
    return 1e18;
  LL T = B / r;
  x = Mul((C / r) % T, x % T, T);
  if ((DB)A * x > 1e18)
    return 1e18;
  return A * x;
}
int main() {
  scanf("%lld", &n);
  n <<= 1;
  ans = n - 1;
  for (int S = sqrt(n), i = 2; i <= S; i++)
    if (!(n % i))
      ans = min(ans, Solve(n / i, i, i - 1)),
      ans = min(ans, Solve(i, n / i, n / i - 1));
  printf("%lld\\n", ans);
  return 0;
}

Error: TLE

Fixed submission:

#include <cmath>
#include <cstdio>
using namespace std;
typedef long long LL;

int S;
LL n;

int main() {
  scanf("%lld", &n);
  S = sqrt(n) + 1;
  n <<= 3;
  while ((LL)S * S % n != 1)
    S++;
  printf("%d\\n", (S - 1) >> 1);
  return 0;
}
Problem p02541 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <math.h>
#include <vector>
using namespace std;
long long extgcd(long long a, long long b, long long &x, long long &y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  }
  long long d = extgcd(b, a % b, y, x);
  y -= (a / b) * x;
  return d;
}
int main() {
  long long N;
  cin >> N;
  N *= 2;
  long long M = N;
  vector<long long> d;
  for (long long i = 2; i * i <= M; i++) {
    if (M % i == 0) {
      long long k = 1;
      while (M % i == 0) {
        M /= i;
        k *= i;
      }
      d.push_back(k);
    }
  }
  if (M != 1)
    d.push_back(M);
  long long answer = N;
  long long l = 1;
  for (int i = 0; i < d.size(); i++)
    l *= 2;
  for (long long i = 0; i < l; i++) {
    long long dev = 1;
    long long judge = 1;
    for (int j = 0; j < d.size(); j++) {
      if ((i % (judge * 2)) / judge == 1)
        dev *= d[j];
      judge *= 2;
    }
    long long x, y;
    extgcd(N / dev, dev, x, y);
    y *= -1;
    if (y > 0)
      y %= (N / dev);
    else {
      y += (abs(y) / (N / dev) + 1) * (N / dev);
    }
    answer = min(answer, y * dev);
  }
  cout << answer << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <math.h>
using namespace std;
int main() {
  long long N;
  cin >> N;
  N *= 2;
  long long i = 1;
  long long answer = -1;
  while (answer == -1) {
    long long K = N * i;
    long long R = K;
    long long L = 1;
    while (R - L != 1) {
      long long med = (L + R) / 2;
      if (K / med < (med + 1))
        R = med;
      else {
        if (med * (med + 1) > K)
          R = med;
        else
          L = med;
      }
    }
    if (L * (L + 1) == K) {
      answer = L;
      break;
    }
    i++;
  }
  cout << answer << endl;

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

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

using ull = unsigned long long;
using ll = long long;
using ld = long double;

const int mod = 1e9 + 7;
const int inf = INT_MAX;

vector<ll> prime_factorize(ll n) {
  vector<ll> res;
  for (int i = 2; (ll)i * i <= n; i++) {
    if (n % i == 0) {
      res.emplace_back(1);
      while (n % i == 0) {
        n /= i;
        res.back() *= i;
      }
    }
  }
  if (n > 1) {
    res.emplace_back(n);
  }
  return res;
}

ll extended_euclid(ll a, ll b, ll &x, ll &y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  }
  ll x1, y1;
  ll d = extended_euclid(b, a % b, x1, y1);
  x = y1;
  y = x1 - y1 * (a / b);
  return d;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  ll n;
  cin >> n;
  n *= 2;

  auto factor = prime_factorize(n);

  ll min_k = LLONG_MAX;
  for (int mask = 0; mask < (1 << factor.size()); mask++) {
    ll a = 1, b = 1;
    for (int i = 0; i < factor.size(); i++) {
      if (mask & (1 << i)) {
        b *= factor[i];
      } else
        a *= factor[i]; // p1, p2, b*p2 = a*p1 + 1 = by - ax = 1
    }
    //-a(x - k*b) + b(y - k*a) = 1, ax + by = 1
    ll x0, y0;
    extended_euclid(a, b, x0, y0);
    x0 = -x0;

    ll limit = (ll)1e18 / max(a, b);
    ll lo = -limit, hi = limit;
    while (lo < hi) {
      ll mid = lo + (hi - lo + 1) / 2;
      if (x0 - mid * b > 0 and y0 - mid * a > 0)
        lo = mid;
      else
        hi = mid - 1;
    }
    min_k = min(min_k, b * (y0 - lo * a) - 1);
  }
  cout << min_k << '\\n';
  return 0;
}

Error: TLE

Fixed submission:

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

using ull = unsigned long long;
using ll = long long;
using ld = long double;

const int mod = 1e9 + 7;
const int inf = INT_MAX;

vector<ll> prime_factorize(ll n) {
  vector<ll> res;
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      res.emplace_back(1);
      while (n % i == 0) {
        n /= i;
        res.back() *= i;
      }
    }
  }
  if (n > 1) {
    res.emplace_back(n);
  }
  return res;
}

ll extended_euclid(ll a, ll b, ll &x, ll &y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  }
  ll x1, y1;
  ll d = extended_euclid(b, a % b, x1, y1);
  x = y1;
  y = x1 - y1 * (a / b);
  return d;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  ll n;
  cin >> n;
  n *= 2;

  auto factor = prime_factorize(n);

  ll min_k = LLONG_MAX;
  for (int mask = 0; mask < (1 << factor.size()); mask++) {
    ll a = 1, b = 1;
    for (int i = 0; i < factor.size(); i++) {
      if (mask & (1 << i)) {
        b *= factor[i];
      } else
        a *= factor[i]; // p1, p2, b*p2 = a*p1 + 1 = by - ax = 1
    }
    //-a(x - k*b) + b(y - k*a) = 1, ax + by = 1
    ll x0, y0;
    extended_euclid(a, b, x0, y0);
    x0 = -x0;

    ll limit = (ll)1e18 / max(a, b);
    ll lo = -limit, hi = limit;
    while (lo < hi) {
      ll mid = lo + (hi - lo + 1) / 2;
      if (x0 - mid * b > 0 and y0 - mid * a > 0)
        lo = mid;
      else
        hi = mid - 1;
    }
    min_k = min(min_k, b * (y0 - lo * a) - 1);
  }
  cout << min_k << '\\n';
  return 0;
}
Problem p02541 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define rep(i, N) for (int i = 0; i < (int)N; i++)
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
static inline void PUT(char c) {
  static char buf[1 << 15], *ptr = buf;
  if (ptr == buf + strlen(buf) || c == 0) {
    fwrite(buf, 1, ptr - buf, stdout), ptr = buf;
  }
  *ptr++ = c;
}
static inline long IN(void) {
  long x = 0, f = 0, c = getchar();
  while (c < 48 || c > 57) {
    f ^= c == 45, c = getchar();
  }
  while (c > 47 && c < 58) {
    x = x * 10 + c - 48, c = getchar();
  }
  return f ? -x : x;
}
static inline void OUT(long a) {
  if (a < 0)
    PUT('-'), a = -a;
  int d[40], i = 0;
  do {
    d[i++] = a % 10;
  } while (a /= 10);
  while (i--) {
    PUT(d[i] + 48);
  }
  PUT('\\n');
}
// https://atcoder.jp/contests/acl1/submissions/16917558
static inline long GCD(long a, long b) { return !b ? a : GCD(b, a % b); }
// static inline long LCM(long a,long b){return a*b/GCD(a,b);}
static inline long Min(long a, long b) { return a < b ? a : b; }
static inline long Euclid(long a, long b, long &x, long &y) {
  if (!b) {
    x = 1, y = 0;
    return a;
  }
  long ret = Euclid(b, a % b, x, y), t = x;
  x = y, y = t - (a / b) * y;
  return ret;
}
static inline long Calc(long i, long j, long ref) {
  long a, b;
  Euclid(i, j, b, a);
  b = (b % j + j) % j;
  return Min(ref, i * b - 1);
}
int main(void) {
  long N = IN(), A = N - 1;
  if (N == 1) {
    return puts("1"), 0;
  }
  N *= 2;
  for (long i = 2; i * i <= N; i++) {
    if (N % i) {
      continue;
    }
    if (GCD(i, N / i) > 1) {
      continue;
    }
    A = Calc(i, N / i, A);
    A = Calc(N / i, i, A);
  }
  return OUT(A), 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define rep(i, N) for (int i = 0; i < (int)N; i++)
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
static inline void PUT(char c) {
  static char buf[1 << 15], *ptr = buf;
  if (ptr == buf + strlen(buf) || c == 0) {
    fwrite(buf, 1, ptr - buf, stdout), ptr = buf;
  }
  *ptr++ = c;
}
static inline long IN(void) {
  long x = 0, f = 0, c = getchar();
  while (c < 48 || c > 57) {
    f ^= c == 45, c = getchar();
  }
  while (c > 47 && c < 58) {
    x = x * 10 + c - 48, c = getchar();
  }
  return f ? -x : x;
}
static inline void OUT(long a) {
  if (a < 0)
    PUT('-'), a = -a;
  int d[40], i = 0;
  do {
    d[i++] = a % 10;
  } while (a /= 10);
  while (i--) {
    PUT(d[i] + 48);
  }
  PUT('\\n');
}
static inline long GCD(long a, long b) { return !b ? a : GCD(b, a % b); }
static inline long LCM(long a, long b) { return a * b / GCD(a, b); }
int main() {
  long N = IN(), A = 9e18, i = 0;
  while (A > N) {
    if (((i + 1) * (i + 2) / 2) % N == 0) {
      A = i + 1;
    }
    i++;
  }
  return OUT(A), 0;
}
Problem p02541 (C++) — buggy submission, verdict: Runtime Error

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

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

long long extend_gcd(long long a, long long b, long long &x, long long &y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  } else {
    long long d = extend_gcd(b, a % b, y, x);
    y -= a / b * x;
    return d;
  }
}

int main() {
  long long n;
  scanf("%lld", &n);
  if (n == 1 << 0 or n == 1 << 1 or n == 1 << 2 or n == 1 << 3 or n == 1 << 4 or
      n == 1 << 5 or n == 1 << 6 or n == 1 << 7 or n == 1 << 8 or n == 1 << 9 or
      n == 1 << 10 or n == 1 << 11 or n == 1 << 12 or n == 1 << 13 or
      n == 1 << 14 or n == 1 << 15 or n == 1 << 16 or n == 1 << 17 or
      n == 1 << 18 or n == 1 << 19 or n == 1 << 20 or n == 1 << 21 or
      n == 1 << 22) {
    cout << n * 2 - 1 << endl;
    return 0;
  }

  vector<long long> primes;
  for (long long i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      long long tmp = 1;
      while (n % i == 0) {
        tmp *= i;
        n /= i;
      }
      primes.push_back(tmp);
    }
  }
  if (n != 1) {
    primes.push_back(n);
  }

  if (primes[0] % 2 == 0) {
    primes[0] *= 2;
  } else {
    primes.push_back(2);
  }

  long long ans = 1e16;
  for (long long i = 0; i < (1 << primes.size()); ++i) {
    long long a = 1;
    long long b = 1;
    for (int j = 0; j < primes.size(); ++j) {
      if (i & (1 << j)) {
        a *= primes[j];
      } else {
        b *= primes[j];
      }
    }
    if (a == 1 or b == 1) {
      continue;
    }
    long long x = 1;
    long long y = 1;
    extend_gcd(a, b, x, y);
    long long k = min(a * abs(x), b * abs(y));
    if (k == 0) {
      continue;
    }
    ans = min(ans, k);
  }

  cout << ans << endl;

  return 0;
}

Error: 0

Fixed submission:

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

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

long long extend_gcd(long long a, long long b, long long &x, long long &y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  } else {
    long long d = extend_gcd(b, a % b, y, x);
    y -= a / b * x;
    return d;
  }
}

int main() {
  long long n;
  scanf("%lld", &n);

  vector<long long> primes;
  for (long long i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      long long tmp = 1;
      while (n % i == 0) {
        tmp *= i;
        n /= i;
      }
      primes.push_back(tmp);
    }
  }
  if (n != 1) {
    primes.push_back(n);
  }

  if (primes[0] % 2 == 0) {
    primes[0] *= 2;
  } else {
    primes.push_back(2);
  }

  long long ans = 1e16;
  for (long long i = 0; i < (1 << primes.size()); ++i) {
    long long a = 1;
    long long b = 1;
    for (int j = 0; j < primes.size(); ++j) {
      if (i & (1 << j)) {
        a *= primes[j];
      } else {
        b *= primes[j];
      }
    }
    if (a == 1 or b == 1) {
      continue;
    }
    long long x = 1;
    long long y = 1;
    extend_gcd(a, b, x, y);
    long long k = min(a * abs(x), b * abs(y));
    if (k == 0) {
      continue;
    }
    ans = min(ans, k);
  }

  cout << ans << endl;

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

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
const int N = (int)2e5 + 7;
const int K = 18;
int n;
int dif;
int q;
int a[N];
int u[K][N];
ll f[K][N];
int u2[K][N];
ll f2[K][N];

ll compute1(int x, int lim) {
  ll sol = x - 1;
  for (int k = K - 1; k >= 0; k--) {
    if (u[k][x] <= lim) {
      sol += f[k][x] - (1 << k);
      x = u[k][x];
    }
  }
  return sol;
}

ll compute2(int x, int lim) {
  ll sol = x;
  for (int k = K - 1; k >= 0; k--) {
    if (lim <= u2[k][x]) {
      sol += f2[k][x];
      x = u2[k][x];
    }
  }
  return sol;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);

  cin >> n >> dif;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  a[n + 1] = a[n] + dif;
  int j = 1;
  for (int i = 1; i <= n; i++) {
    while (a[j] - a[i] < dif) {
      j++;
    }
    u[0][i] = j;
    f[0][i] = j;
  }
  a[0] = a[1] - dif;
  j = n;
  for (int i = n; i >= 1; i--) {
    while (a[i] - a[j] < dif) {
      j--;
    }
    u2[0][i] = j;
    f2[0][i] = j;
  }
  for (int k = 1; k < K; k++) {
    for (int i = 1; i <= n; i++) {
      if (u[k - 1][i] == n + 1) {
        u[k][i] = n + 1;
      } else {
        f[k][i] = f[k - 1][i] + f[k - 1][u[k - 1][i]];
        u[k][i] = u[k - 1][u[k - 1][i]];
      }
      /// boooo
      if (u2[k - 1][i] == 0) {
        u2[k][i] = 0;
      } else {
        f2[k][i] = f2[k - 1][i] + f2[k - 1][u2[k - 1][i]];
        u2[k][i] = u2[k - 1][u2[k - 1][i]];
      }
    }
  }
  cin >> q;
  while (q--) {
    int l, r, best = 0, sol = 0;
    cin >> l >> r;
    cout << compute2(r, l) - compute1(l, r) << "\\n";
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
const int N = (int)2e5 + 7;
const int K = 18;
int n;
int dif;
int q;
int a[N];
int u[K][N];

int compute(int x, int lim) {
  int sol = 1;
  for (int k = K - 1; k >= 0; k--) {
    if (u[k][x] <= lim) {
      sol += (1 << k);
      x = u[k][x];
    }
  }
  return sol;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> dif;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  a[n + 1] = a[n] + dif;
  int j = 1;
  for (int i = 1; i <= n; i++) {
    while (a[j] - a[i] < dif) {
      j++;
    }
    u[0][i] = j;
  }
  for (int k = 1; k < K; k++) {
    for (int i = 1; i <= n; i++) {
      if (u[k - 1][i] == n + 1) {
        u[k][i] = n + 1;
      } else {
        u[k][i] = u[k - 1][u[k - 1][i]];
      }
    }
  }
  cin >> q;
  while (q--) {
    int l, r, best = 0, sol = 0;
    cin >> l >> r;
    best = compute(l, r);
    for (int i = l; i <= r; i++) {
      if (compute(l, i) + compute(i, r) - 1 == best) {
        sol++;
      }
    }
    cout << sol << "\\n";
  }
  return 0;
}
Problem p02547 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n;
  cin >> n;
  vector<vector<int>> s(n, vector<int>(2));
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int f = 0; f < 2; f++) {
      cin >> s.at(i).at(f);
    }
  }
  for (int i = 0; i < n; i++) {
    if (s.at(i).at(0) == s.at(i).at(1))
      ans++;
    if (ans == 3)
      break;
    else if (s.at(i).at(0) != s.at(i).at(1))
      ans = 0;
  }
  if (ans >= 3)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

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


Fixed submission:

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

int main() {
  int n;
  cin >> n;
  vector<vector<int>> s(n, vector<int>(2));
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int f = 0; f < 2; f++) {
      cin >> s.at(i).at(f);
    }
  }
  for (int i = 0; i < n; i++) {
    if (s.at(i).at(0) == s.at(i).at(1))
      ans++;
    if (ans == 3)
      break;
    else if (s.at(i).at(0) != s.at(i).at(i))
      ans = 0;
  }
  if (ans >= 3)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
Problem p02547 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <vector>

using namespace std;
struct XX {
  int s;
  int e;
};

class xxGreater {
public:
  bool operator()(const XX &riLeft, const XX &riRight) const {
    // 第2条件
    if ((riLeft.s) == (riRight.s)) {
      return riLeft.e <
             riRight.e; //<:昇順(小さいものから順番)、>:降順(大きいものから順番)
                        // プライオリティキューの場合は >
                        // で、top()すると値の小さいものがとれる
    }
    // 第1条件
    return (riLeft.s) > (riRight.s);
  }
};

int main(int argc, const char *argv[]) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> ans;
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    if (a == b) {
      ans.push_back(i);
    }
  }

  int f = 0;
  if (ans.size() > 2) {
    for (int i = 0; i < n - 2; i++) {
      if (ans[i + 2] - ans[i + 1] == 1 && ans[i + 1] - ans[i] == 1) {
        f = 1;
      }
    }
  }

  if (f == 1) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <vector>

using namespace std;
struct XX {
  int s;
  int e;
};

class xxGreater {
public:
  bool operator()(const XX &riLeft, const XX &riRight) const {
    // 第2条件
    if ((riLeft.s) == (riRight.s)) {
      return riLeft.e <
             riRight.e; //<:昇順(小さいものから順番)、>:降順(大きいものから順番)
                        // プライオリティキューの場合は >
                        // で、top()すると値の小さいものがとれる
    }
    // 第1条件
    return (riLeft.s) > (riRight.s);
  }
};

int main(int argc, const char *argv[]) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> ans;
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    if (a == b) {
      ans.push_back(i);
    }
  }

  int f = 0;
  for (int i = 0; i < n - 2; i++) {
    if (ans[i + 2] - ans[i + 1] == 1 && ans[i + 1] - ans[i] == 1) {
      f = 1;
    }
  }

  if (f == 1) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
Problem p02547 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int N, A;
  A = 0;
  cin >> N;
  vector<int> D1(N), D2(N);

  for (int i = 0; i < N; i++) {
    cin >> D1.at(i);
    cin >> D2.at(i);
  }
  for (int i = 0; i < N - 2; i++) {
    if (D1.at(i) == D2.at(i) && D1.at(i + 1) == D2.at(i + 1) &&
        D1.at(i + 2) == D2.at(i + 2)) {
      A = 1;
    }
  }
  if (A == 1) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Error: 0

Fixed submission:

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

int main() {
  int N, A;
  A = 0;
  vector<int> D1(N), D2(N);
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> D1.at(i);
    cin >> D2.at(i);
  }
  for (int i = 0; i < N - 2; i++) {
    if (D1.at(i) == D2.at(i) && D1.at(i + 1) == D2.at(i + 1) &&
        D1.at(i + 2) == D2.at(i + 2)) {
      A = 1;
    }
  }
  if (A == 1) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
Problem p02547 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <list>
#include <math.h>
#include <numeric>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

int main() {

  int N;
  cin >> N;

  int D1, D2;

  vector<int> a;

  for (int i = 1; i <= N; i++) {
    cin >> D1 >> D2;
    if (D1 == D2) {
      a.push_back(i);
    }
  }

  bool jdg = false;

  if (a.size() <= 2) {
    cout << "No" << endl;
  } else {
    for (int i = 0; i < a.size() - 2; i++) {
      if (a[i + 1] == a[i] + 1 && a[i + 2] == a[i] + 2) {
        jdg = true;
        break;
      }
    }

    if (jdg == true) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <list>
#include <math.h>
#include <numeric>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

int main() {

  int N;
  cin >> N;

  int D1, D2;

  vector<int> a;

  for (int i = 1; i <= N; i++) {
    cin >> D1 >> D2;
    if (D1 == D2) {
      a.push_back(i);
    }
  }

  bool jdg = false;

  for (int i = 0; i < a.size() - 2; i++) {
    if (a[i + 1] == a[i] + 1 && a[i + 2] == a[i] + 2) {
      jdg = true;
      break;
    }
  }

  if (jdg == true) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}