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

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

int main() {
  int N, ABC[3];
  cin >> N >> ABC[0] >> ABC[1] >> ABC[2];
  vector<string> s(N);
  for (string &t : s)
    cin >> t;

  string ans;
  function<char(int, int)> f = [&](int d, int md) -> char {
    if (ABC[0] < 0 || ABC[1] < 0 || ABC[2] < 0)
      return 'X';
    if (d >= md)
      return 'O';

    ABC[s[d][0] - 'A']--;
    ABC[s[d][1] - 'A']++;
    char c = f(d + 1, md);
    ABC[s[d][0] - 'A']++;
    ABC[s[d][1] - 'A']--;
    if (c != 'X')
      return s[d][1];

    ABC[s[d][1] - 'A']--;
    ABC[s[d][0] - 'A']++;
    c = f(d + 1, md);
    ABC[s[d][1] - 'A']++;
    ABC[s[d][0] - 'A']--;
    if (c != 'X')
      return s[d][0];

    return 'X';
  };

  for (int i = 0; i < N; i++) {
    char c = f(i, min(i + 2, N));
    if (c == 'X') {
      cout << "No" << endl;
      return 0;
    }
    for (int j = 0; j < 2; j++)
      if (s[i][j] == c)
        ABC[s[i][j] - 'A']++;
      else
        ABC[s[i][j] - 'A']--;
    ans += c;
  }

  cout << "Yes" << endl;
  for (char c : ans)
    cout << c << endl;
}


Error: 0

Fixed submission:

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

int main() {
  int N, ABC[3];
  cin >> N >> ABC[0] >> ABC[1] >> ABC[2];
  vector<string> s(N);
  for (string &t : s)
    cin >> t;

  string ans;
  function<char(int, int)> f = [&](int d, int md) -> char {
    if (ABC[0] < 0 || ABC[1] < 0 || ABC[2] < 0)
      return 'X';
    if (d >= md)
      return 'O';

    ABC[s[d][0] - 'A']--;
    ABC[s[d][1] - 'A']++;
    char c = f(d + 1, md);
    ABC[s[d][0] - 'A']++;
    ABC[s[d][1] - 'A']--;
    if (c != 'X')
      return s[d][1];

    ABC[s[d][1] - 'A']--;
    ABC[s[d][0] - 'A']++;
    c = f(d + 1, md);
    ABC[s[d][1] - 'A']++;
    ABC[s[d][0] - 'A']--;
    if (c != 'X')
      return s[d][0];

    return 'X';
  };

  for (int i = 0; i < N; i++) {
    char c = f(i, min(i + 4, N));
    if (c == 'X') {
      return -1;
      cout << "No" << endl;
      return 0;
    }
    ans += c;
  }

  cout << "Yes" << endl;
  for (char c : ans)
    cout << c << endl;
}
Problem p02692 (C++) — buggy submission, verdict: Runtime Error

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

vector<ll> v;
vector<char> ans;
bool ok = 1;
ll n, t;
ll ind = 0;

void solve(string s) {
  if (!v[s[0] - 'A'] && !v[s[1] - 'A']) {
    ok = 0;
    return;
  }
  if (!v[s[0] - 'A'])
    v[s[0] - 'A']++, v[s[1] - 'A']--, ans[ind++] = s[0];
  else if (!v[s[1] - 'A'])
    v[s[1] - 'A']++, v[s[0] - 'A']--, ans[ind++] = s[1];
  else {
    if (t == 2) {
      if (n--) {
        string c;
        cin >> c;
        if (s[0] == c[0] || s[0] == c[1])
          v[s[0] - 'A']++, v[s[1] - 'A']--, ans[ind++] = s[0];
        else
          v[s[1] - 'A']++, v[s[0] - 'A']--, ans[ind++] = s[1];
        solve(c);
      } else
        v[s[0] - 'A']++, v[s[1] - 'A']--, ans[ind++] = s[0];
    } else {
      if (v[s[1] - 'A'] == t - 1)
        v[s[0] - 'A']++, v[s[1] - 'A']--, ans[ind++] = s[0];
      else
        v[s[1] - 'A']++, v[s[0] - 'A']--, ans[ind++] = s[1];
    }
  }
}

int main() {
  cin >> n;
  v.resize(3), ans.resize(n);
  cin >> v[0] >> v[1] >> v[2];
  t = v[0] + v[1] + v[2];
  while (n-- > 0) {
    string s;
    cin >> s;
    if (!ok)
      continue;
    solve(s);
  }
  if (n == 0 || !ok)
    cout << "No";
  else {
    cout << "Yes\\n";
    for (char c : ans)
      cout << c << "\\n";
  }
  return 0;
}


Error: 0

Fixed submission:

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

vector<ll> v;
vector<char> ans;
bool ok = 1;
ll n, t;
ll ind = 0;

void solve(string s) {
  if (!v[s[0] - 'A'] && !v[s[1] - 'A']) {
    ok = 0;
    return;
  }
  if (!v[s[0] - 'A'])
    v[s[0] - 'A']++, v[s[1] - 'A']--, ans[ind++] = s[0];
  else if (!v[s[1] - 'A'])
    v[s[1] - 'A']++, v[s[0] - 'A']--, ans[ind++] = s[1];
  else {
    if (t == 2) {
      if (n--) {
        string c;
        cin >> c;
        if (s[0] == c[0] || s[0] == c[1])
          v[s[0] - 'A']++, v[s[1] - 'A']--, ans[ind++] = s[0];
        else
          v[s[1] - 'A']++, v[s[0] - 'A']--, ans[ind++] = s[1];
        solve(c);
      } else
        v[s[0] - 'A']++, v[s[1] - 'A']--, ans[ind++] = s[0];
    } else {
      if (v[s[1] - 'A'] == t - 1)
        v[s[0] - 'A']++, v[s[1] - 'A']--, ans[ind++] = s[0];
      else
        v[s[1] - 'A']++, v[s[0] - 'A']--, ans[ind++] = s[1];
    }
  }
}

int main() {
  cin >> n;
  v.resize(3), ans.resize(n);
  cin >> v[0] >> v[1] >> v[2];
  t = v[0] + v[1] + v[2];
  while (n--) {
    string s;
    cin >> s;
    if (!ok)
      continue;
    solve(s);
  }
  if (n == 0 || !ok)
    cout << "No";
  else {
    cout << "Yes\\n";
    for (char c : ans)
      cout << c << "\\n";
  }
  return 0;
}
Problem p02693 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define rp(i, n) for (int i = 1; i <= (int)n; i++)
int main() {
  int k, a, b;
  int s = 0;
  cin >> k >> a >> b;
  for (int i = a; i <= b; i++) {
    if (i % k == 0)
      s = 1;
  }
  if (s == 1)
    cout << "OK" << endl;
  else
    cout << "NG" << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define rp(i, n) for (int i = 1; i <= (int)n; i++)
int main() {
  int k, a, b;
  int s = 0;
  cin >> k >> a >> b;
  for (int i = a; i <= b; a++) {
    if (i % k == 0)
      s = 1;
  }
  if (s == 1)
    cout << "OK" << endl;
  else
    cout << "NO" << endl;
}
Problem p02693 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int main() {
  int K, A, B, i, j = 0;
  cin >> K >> A >> B;
  for (i = A; i <= B; i++) {
    if (i % K == 0) {
      j++;
    }
  }
  if (j > 0)
    cout << "OK";
  else
    cout << "NG";
}

Error: 0

Fixed submission:

#include <stdio.h>
#include <string.h>

int main() {
  int k, a, b, i;
  bool ok = false;
  if (a % k == 0) {
    ok = true;
  }
  for (i = a; i <= b; i++) {
    if (i % k == 0) {
      ok = true;
      break;
    }
  }
  if (ok) {
    printf("OK\\n");
  } else {
    printf("NG\\n");
  }

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

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

int main() {
  int k, a, b;
  cin >> k >> a >> b;
  if (a <= (b / k) * k) {
    cout << "OK" << endl;
  } else {
    cout << "NG" << endl;
  }
}


Error: TLE

Fixed submission:

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

int main() {
  int K, A, B;
  cin >> K >> A >> B;
  while (true) {
    bool add = false;
    for (int i = 0; i < 100; i++) {
      if (A <= K * i && B >= K * i) {
        add = true;
      }
    }
    if (add) {
      cout << "OK" << endl;
    } else {
      cout << "NG" << endl;
    }
  }
}
Problem p02693 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  int k;
  int a, b;
  cin >> k;
  cin >> a >> b;
  bool flag = false;
  for (int i = a; i <= b; ++i) {
    if (i % k == 0)
      flag = true;
  }
  if (flag)
    cout << "OK" << endl;
  else
    cout << "NG" << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int k;
  int a, b;
  cin >> a >> b;
  bool flag = true;
  for (int i = a; i <= b; ++i) {
    if (i % k == 0)
      flag = false;
  }
  if (flag)
    cout << "OK" << endl;
  else
    cout << "NG" << endl;
  return 0;
}
Problem p02693 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  int a, b, c, i = 0, k = 0;
  cin >> a;
  cin >> b >> c;
  i = b;
  while (i <= c) {
    if (i % a == 0) {
      k = 1;
      cout << "OK";
      break;
    }
    i += 1;
  }
  if (k == 0)
    cout << "NG";
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int a, b, c, i = 0, k = 0;
  cin >> a;
  cin >> b >> c;
  i = b;
  while (i <= c) {
    if (i % a == 0) {
      k = 1;
      cout << "OK";
    }
  }
  if (k == 0)
    cout << "NG";
}
Problem p02693 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int k = 0;
  int a = 0;
  int b = 0;
  cin >> k >> a >> b;
  bool ans = false;
  int e = b - a + 1;

  // aからｂの数を配列で受け取って一つずつｋで割った余りを調べる
  vector<int> c(b - a + 1);

  for (int i = 0; i < e; i++) {
    c.at(i) = a;
    a++;
  }

  for (int i = 0; i < e; i++) {
    if (c.at(i) % k == 0) {
      ans = true;
    }
  }

  if (ans) {
    cout << "OK" << endl;
  } else {
    cout << "NG" << endl;
  }
}

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


Fixed submission:

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

int main() {
  int k = 0;
  int a = 0;
  int b = 0;
  cin >> k >> a >> b;
  bool ans = false;

  // aからｂの数を配列で受け取って一つずつｋで割った余りを調べる
  vector<int> c(b - a + 1);

  for (int i = 0; i < b - a; i++) {
    a = c.at(i);
    a++;
  }

  for (int i = 0; i < b - a; i++) {
    if (c.at(i) % k == 0) {
      ans = true;
    }
  }

  if (ans) {
    cout << "OK" << endl;
  } else {
    cout << "NG" << endl;
  }
}
Problem p02693 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main() {

  int A, B, K;

  cin >> K;
  cin >> A >> B;

  int a = A / K;
  int b1 = K * a, b2 = K * (a + 1);

  if (b1 == A || (b2 > A && b2 <= B))
    cout << "OK" << endl;
  else
    cout << "NG" << endl;

  return 0;
}

Error: 9

Fixed submission:

#include <iostream>
using namespace std;

int main() {

  int A, B, K;

  cin >> K;
  cin >> A >> B;

  int a = A / K;
  int b1 = K * a, b2 = K * (a + 1);

  if (b1 == A || (b2 > A && b2 < B))
    cout << "OK" << endl;
  else
    cout << "NG" << endl;

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

#include <iostream>

using namespace std;

signed main() {
  int k, a, b;
  // Sample 1
  // k = 7
  // a = 500
  // b = 600
  // Expected Output: "OK"

  // Sample 2
  // k = 4
  // a = 5
  // b = 7
  // Expected Output: "NG"

  // Sample 3
  // k = 1
  // a = 11
  // b = 11
  // Expected Output: "OK"

  cin >> k;
  cin >> a;
  cin >> b;

  for (int i = a; i <= b; ++i) // value is a is not being read correctly
  {
    if (i % k == 0) {
      cout << "OK"
           << "\\n";
      return 0;
    }
  }
  cout << "NG"
       << "\\n";

  return 0;
}


Error: 1

Fixed submission:

#include <iostream>

using namespace std;

int main(int argc, char const *argv[]) {
  int k, a, b;
  // Sample 1
  // k = 7
  // a = 500
  // b = 600
  // Expected Output: "OK"

  // Sample 2
  // k = 4
  // a = 5
  // b = 7
  // Expected Output: "NG"

  // Sample 3
  // k = 1
  // a = 11
  // b = 11
  // Expected Output: "OK"

  cin >> k;
  cin >> a;
  cin >> b;

  for (int i = a; i <= b; ++i) // value is a is not being read correctly
  {
    if (i % k == 0) {
      cout << "OK"
           << "";
      return 1;
    }
  }
  cout << "NG"
       << "";

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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// #define P pair<ll,ll>
#define FOR(I, A, B) for (ll I = ll(A); I < ll(B); ++I)
#define FORR(I, A, B) for (ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x, t, f) ((x) ? (t) : (f))
#define SORT(x) (sort(x.begin(), x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x, v)                                                             \\
  (lower_bound(x.begin(), x.end(), v) - x.begin()) // xi>=v  x is sorted
#define POSU(x, v)                                                             \\
  (upper_bound(x.begin(), x.end(), v) - x.begin()) // xi>v  x is sorted
#define NUM(x, v) (POSU(x, v) - POSL(x, v))        // x is sorted
#define REV(x) (reverse(x.begin(), x.end()))       // reverse
ll gcd(ll a, ll b) {
  if (a % b == 0)
    return b;
  return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
  ll c = gcd(a, b);
  return ((a / c) * (b / c) * c);
}
#define NEXTP(x) next_permutation(x.begin(), x.end())
const ll INF = ll(1e16) + ll(7);
const ll MOD = 1000000007LL;
#define out(a) cout << fixed << setprecision((a))
// tie(a,b,c) = make_tuple(10,9,87);
#define pop(a) __builtin_popcount((a))
ll keta(ll a) {
  ll r = 0;
  while (a) {
    a /= 10;
    r++;
  }
  return r;
}

int main() {

  ll a, b, k;
  cin >> k >> a >> b;
  bool ok = false;
  FOR(i, a, b + 1) if ((i % k) == 0) ok = true;
  if (ok) {
    cout << "OK" << endl;
  } else {
    cout << "NG" << endl;
  }
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// #define P pair<ll,ll>
#define FOR(I, A, B) for (ll I = ll(A); I < ll(B); ++I)
#define FORR(I, A, B) for (ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x, t, f) ((x) ? (t) : (f))
#define SORT(x) (sort(x.begin(), x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x, v)                                                             \\
  (lower_bound(x.begin(), x.end(), v) - x.begin()) // xi>=v  x is sorted
#define POSU(x, v)                                                             \\
  (upper_bound(x.begin(), x.end(), v) - x.begin()) // xi>v  x is sorted
#define NUM(x, v) (POSU(x, v) - POSL(x, v))        // x is sorted
#define REV(x) (reverse(x.begin(), x.end()))       // reverse
ll gcd(ll a, ll b) {
  if (a % b == 0)
    return b;
  return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
  ll c = gcd(a, b);
  return ((a / c) * (b / c) * c);
}
#define NEXTP(x) next_permutation(x.begin(), x.end())
const ll INF = ll(1e16) + ll(7);
const ll MOD = 1000000007LL;
#define out(a) cout << fixed << setprecision((a))
// tie(a,b,c) = make_tuple(10,9,87);
#define pop(a) __builtin_popcount((a))
ll keta(ll a) {
  ll r = 0;
  while (a) {
    a /= 10;
    r++;
  }
  return r;
}

int main() {

  ll a, b, k;
  bool ok = false;
  FOR(i, a, b + 1) if (i % k == 0) ok = true;
  if (ok) {
    cout << "OK" << endl;
  } else {
    cout << "NG" << endl;
  }
}
Problem p02693 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>

int main() {

  int k, a, b;
  int ctr = 0;
  scanf("%d", &k);
  scanf("%d %d", &a, &b);

  for (int i = a; i <= b; i++) {
    if (i % k == 0) {
      ctr = 1;
    }
  }
  if (ctr == 1) {
    printf("OK\\n");
  } else {
    printf("NG\\n");
  }
  return 0;
}

Error: TLE

Fixed submission:


#include <stdio.h>

int main() {

  int K;
  scanf("%d", &K);
  int A;
  int B;
  int tot;
  scanf("%d %d", &A, &B);

  for (int i = A; A <= B; i++) {
    if (i % K == 0) {
      tot++;
    }
  }
  if (tot != 0) {
    printf("OK ");
  } else {
    printf("NG ");
  }

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

#include <iostream>
using namespace std;
int main() {
  int k;
  int a, b;
  cin >> k;
  cin >> a >> b;
  int i = 0;
  while (i < a) {
    i += k;
  }
  if (i > b) {
    cout << "NG\\n";
  } else {
    cout << "OK\\n";
  }
  return 0;
}

Error: 1

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int k;
  int a, b;
  cin >> k;
  cin >> a >> b;
  int i = 0;
  while (i < a) {
    i += k;
  }
  if (i > b) {
    return false;
  }
  return true;
}
Problem p02693 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define mp make_pair
#define pb push_back
#define pii pair<int, int>
#define link(x) for (edge *j = h[x]; j; j = j->next)
#define inc(i, l, r) for (int i = l; i <= r; i++)
#define dec(i, r, l) for (int i = r; i >= l; i--)
const int MAXN = 3e5 + 10;
const double eps = 1e-8;
const int mod = 1e9 + 9;
#define ll long long
using namespace std;
struct edge {
  int t, v;
  edge *next;
} e[MAXN << 1], *h[MAXN], *o = e;
void add(int x, int y, int vul) {
  o->t = y;
  o->v = vul;
  o->next = h[x];
  h[x] = o++;
}
ll read() {
  ll x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-')
      f = -1;
    ch = getchar();
  }
  while (isdigit(ch))
    x = x * 10 + ch - '0', ch = getchar();
  return x * f;
}

int k, a, b;
int main() {
  k = read();
  a = read();
  b = read();
  int x = b / k * k;
  if (x >= a)
    puts("OK");
  else
    puts("NG");
  return 0;
}


Error: 3

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define mp make_pair
#define pb push_back
#define pii pair<int, int>
#define link(x) for (edge *j = h[x]; j; j = j->next)
#define inc(i, l, r) for (int i = l; i <= r; i++)
#define dec(i, r, l) for (int i = r; i >= l; i--)
const int MAXN = 3e5 + 10;
const double eps = 1e-8;
const int mod = 1e9 + 9;
#define ll long long
using namespace std;
struct edge {
  int t, v;
  edge *next;
} e[MAXN << 1], *h[MAXN], *o = e;
void add(int x, int y, int vul) {
  o->t = y;
  o->v = vul;
  o->next = h[x];
  h[x] = o++;
}
ll read() {
  ll x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-')
      f = -1;
    ch = getchar();
  }
  while (isdigit(ch))
    x = x * 10 + ch - '0', ch = getchar();
  return x * f;
}

int k, a, b;
int main() {
  k = read();
  a = read();
  b = read();
  int x = b / k * k;
  if (x >= a)
    return puts("OK");
  else
    puts("NG");
  return 0;
}
Problem p02693 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int k, a, b;
  cin >> k;
  cin >> a >> b;
  for (int i = a; i <= b; i++) {
    if (i % k == 0) {
      cout << "OK" << endl;
      return 0;
    }
  }
  cout << "NG" << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int k, a, b;
  cin >> k;
  cin >> a >> b;
  for (int i = a; i = b; i++) {
    if (i % k == 0) {
      cout << "OK" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
  return 0;
}
Problem p02693 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int K, A, B, flag = 0;
  cin >> K >> A >> B;

  for (int i = A; i <= B; i++) {
    if (i % K == 0) {
      cout << "OK" << endl;
      flag = 1;
      break;
    }
  }
  if (flag != 1) {
    cout << "NG" << endl;
  }
}


Error: WA

Fixed submission:

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

int main() {
  int K, A, B, flag = 0;
  cin >> A >> B;

  for (int i = A; i <= B; i++) {
    if (i % K == 0) {
      cout << "OK" << endl;
      flag = 1;
      break;
    }
  }
  if (flag != 1) {
    cout << "NG" << endl;
  }
}
Problem p02693 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int A, B, K;
  cin >> K;
  scanf("%d%d", &A, &B);
  for (int i = A; i <= B; i++) {
    // printf("%d", i%K);
    if (i % K == 0) {
      printf("OK");
      return 0;
    }
  }
  printf("NG");
  return 0;
}

Error: 2

Fixed submission:

#include <stdio.h>

int main(void) {
  int k, a, b;
  scanf("%d %d %d", &k, &a, &b);
  for (int i = a; i < b; i++) {
    int j = i % k;
    if (j == 0) {
      return printf("OK");
    }
  }
  return 0;
}
Problem p02693 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>

using namespace std;

int main() {
  int K, A, B;
  cin >> K >> A >> B;
  bool flag = 0;
  for (int i = A; i <= B; i++) {
    if (i % K == 0)
      flag = 1;
  }
  if (flag == 1)
    cout << "OK" << endl;
  else
    cout << "NG" << endl;
}


Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  int K, A, B;
  bool flag = 0;
  for (int i = A; i <= B; i++) {
    if (i % K == 0)
      flag = 1;
  }
  if (flag == 1)
    cout << "OK" << endl;
  else
    cout << "NG" << endl;
}
Problem p02693 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int k, a, b;
  cin >> k >> a >> b;
  bool can = false;
  for (int idx = a; idx <= b; idx++) {
    if (idx % k == 0)
      can = true;
  }
  cout << (can ? "OK" : "NG") << endl;
}


Error: WA

Fixed submission:

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

int main() {
  int k, a, b;
  cin >> a >> b;
  for (int idx = a; idx <= b; idx++) {
    if (idx % k == 0)
      cout << "OK" << endl;
  }
  cout << "NO" << endl;
}
Problem p02693 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define mem(a, v) memset((a), (v), sizeof(a))
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define FORE(i, a, n) for (int i = (a); i <= (n); ++i)
#define mp(a, b) make_pair(a, b)
#define pb(a) push_back(a)

#define anal '\\n'

#define mod 1000000009

typedef long long ll;

int main() {

  IOS;

#ifndef ONLINE_JUDGE
  freopen("input.in", "r", stdin);
  freopen("output.in", "w", stdout);
#else
// online submission
#endif

  // -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-

  int k, a, b;
  cin >> k >> a >> b;

  while (a <= b) {
    if (a % k == 0) {
      cout << "OK";
      return 0;
    }
    a++;
  }
  cout << "NG";
  return 0;
}


Error: TLE

Fixed submission:

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

#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define mem(a, v) memset((a), (v), sizeof(a))
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define FORE(i, a, n) for (int i = (a); i <= (n); ++i)
#define mp(a, b) make_pair(a, b)
#define pb(a) push_back(a)

#define anal '\\n'

#define mod 1000000009

typedef long long ll;

int main() {

  IOS;

#ifndef ONLINE_JUDGE
  freopen("input.in", "r", stdin);
  freopen("output.in", "w", stdout);
#else
// online submission
#endif

  // -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-

  int k, a, b;
  cin >> k >> a >> b;

  while (a <= b) {
    if (a % k == 0) {
      cout << "OK";
      return 0;
    }
  }
  cout << "NG";
  return 0;
}
Problem p02693 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  int k, a, b;
  cin >> k >> a >> b;
  bool f = 0;
  for (int i = a; i <= b; i++)
    if (i % k == 0)
      f = 1;
  cout << (f ? "OK" : "NG") << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int k, a, b;
  cin >> k >> a >> b;
  bool f = 0;
  for (int i = a; a <= b; i++)
    if (i % k == 0)
      f = 1;
  cout << (f ? "OK" : "NG") << endl;
}
Problem p02693 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18, MOD = 1e9 + 7;
const int INT_INF = 1e9, INT_MOD = 1e9 + 7;
#define rep(i, N) for (int i = 0; i < N; i++)
typedef pair<int, int> Pi;
typedef pair<double, double> P;
signed main() {
  int k, a, b;
  cin >> k >> a >> b;
  for (int i = a; i <= b; i++) {
    if (i % k == 0) {
      cout << "OK" << endl;
      return 0;
    }
  }
  cout << "NG" << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18, MOD = 1e9 + 7;
const int INT_INF = 1e9, INT_MOD = 1e9 + 7;
#define rep(i, N) for (int i = 0; i < N; i++)
typedef pair<int, int> Pi;
typedef pair<double, double> P;
signed main() {
  int k, a, b;
  cin >> k >> a >> b;
  for (int i = a; i <= b; i++) {
    if (i %= k == 0) {
      cout << "OK" << endl;
      return 0;
    }
  }
  cout << "NG" << endl;
  return 0;
}