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

#include <cstdlib>
#include <iostream>
#include <set>
#include <string>
using namespace std;

int main() {
  int n, m;
  while (cin >> m >> n, m || n) {
    set<int> t;
    for (int i = 0; i < m; ++i)
      t.insert(i + 1);

    set<int>::iterator it = t.begin();
    for (int i = 1; i <= n; ++i) {
      string s;
      cin >> s;
      if (t.size() != 1) {
        if (i % 3 == 0 && i % 5 == 0) {
          if (s != "FizzBuzz") {
            t.erase(it++);
          } else {
            it++;
          }
        } else if (i % 3 == 0) {
          if (s != "Fizz") {
            t.erase(it++);
          } else {
            it++;
          }
        } else if (i % 5 == 0) {
          if (s != "Buzz") {
            t.erase(it++);
          } else {
            it++;
          }
        } else if (i != atoi(s.c_str())) {
          t.erase(it++);
        } else {
          it++;
        }
        if (it == t.end()) {
          it = t.begin();
        }
      }
    }

    for (it = t.begin(); it != t.end(); ++it) {
      if (it != t.begin())
        cout << ' ';
      cout << *it;
    }
    cout << endl;
  }
}

Error: TLE

Fixed submission:

#include <cstdlib>
#include <iostream>
#include <set>
#include <string>
using namespace std;

int main() {
  int n, m;
  while (cin >> m >> n, m || n) {
    set<int> t;
    for (int i = 0; i < m; ++i)
      t.insert(i + 1);

    set<int>::iterator it = t.begin();
    for (int i = 1; i <= n && t.size() != 1; ++i) {
      string s;
      cin >> s;
      if (i % 3 == 0 && i % 5 == 0) {
        if (s != "FizzBuzz") {
          t.erase(it++);
        } else {
          it++;
        }
      } else if (i % 3 == 0) {
        if (s != "Fizz") {
          t.erase(it++);
        } else {
          it++;
        }
      } else if (i % 5 == 0) {
        if (s != "Buzz") {
          t.erase(it++);
        } else {
          it++;
        }
      } else if (i != atoi(s.c_str())) {
        t.erase(it++);
      } else {
        it++;
      }
      if (it == t.end()) {
        it = t.begin();
      }
    }

    for (it = t.begin(); it != t.end(); ++it) {
      if (it != t.begin())
        cout << ' ';
      cout << *it;
    }
    cout << endl;
  }
}
Problem p00221 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
#include <algorithm>
#include <queue>
#include <string.h>
#include <string>
#include <vector>
bool b[2003];

#define REP(a) for (int i = 0; i < a; i++)

int main() {
  bool f = 0;
  int x, m, n, j;
  int prev[2002], next[2002], p, v = 1;
  string c, d;
  cin >> m >> n;
  while (m != 0 || n != 0) {
    x = m;
    REP(m) {
      next[i] = (i + 1) % m;
      prev[i] = (i + m - 1) % m;
    }
    p = 0;
    REP(n) {
      cin >> c;
      if (f == 0) {
        if (c != "Fizz" && (i + 1) % 3 == 0 && (i + 1) % 5 != 0) {
          v = 0;
          m--;
        } else if (c != "Buzz" && (i + 1) % 3 != 0 && (i + 1) % 5 == 0) {
          v = 0;
          m--;
        } else if (c != "FizzBuzz" && (i + 1) % 3 == 0 && (i + 1) % 5 == 0) {
          v = 0;
          m--;
        } else if (atoi(c.c_str()) != i + 1 && (i + 1) % 3 != 0 &&
                   (i + 1) % 5 != 0) {
          v = 0;
          m--;
          //	cout<<'A';
        }
      }
      if (v == 0) {
        prev[next[p]] = prev[p];
        next[prev[p]] = next[p];
        prev[p] = -1;
        v = 1;
      }
      p = next[p];
      if (m == 1)
        f = 1;
    }
    REP(x) {
      if (prev[i] != -1) {
        cout << i + 1;
        p = i;
        break;
      }
    }
    for (v = p + 1; v < x; v++) {
      if (prev[v] != -1)
        cout << " " << v + 1;
    }
    cout << endl;
    cin >> m >> n;
    f = 0;
    j = 1;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;
#include <algorithm>
#include <functional>
#include <queue>
#include <string.h>
#include <string>
#include <vector>
bool b[2001];
#define REP(i, a) for (int i = 1; i <= a; i++)
int main() {
  bool f = 0;
  int x, m, n, j = 1;
  vector<int> a;
  string c, d;
  cin >> m >> n;
  while (m != 0 || n != 0) {
    x = m;
    REP(i, n) { b[i] = 1; }
    REP(i, n) {
      cin >> c;
      if (f == 0) {
        while (1) {
          if (b[j] == 1) {
            break;
          }
          j++;
          if (j == x + 1)
            j = 1;
        }
        if (c != "Fizz" && i % 3 == 0 && i % 5 != 0) {
          b[j] = 0;
          m--;
        } else if (c != "Buzz" && i % 3 != 0 && i % 5 == 0) {
          b[j] = 0;
          m--;
        } else if (c != "FizzBuzz" && i % 3 == 0 && i % 5 == 0) {
          b[j] = 0;
          m--;
        }
        // else if(atoi(c.c_str())!=i){
        //	b[j].second=0;
        //	m--;
        //	cout<<'A';
        // }
      }
      j++;
      if (j == x + 1)
        j = 1;
      if (m == 1)
        f = 1;
    }
    // cout<<m;
    f = 0;
    REP(i, x) {
      if (f == 1 && b[i] == 1)
        cout << " " << i;
      if (i == x)
        cout << endl;
      if (b[i] == 1 && f == 0) {
        cout << i;
        f = 1;
      }
    }
    cin >> m >> n;
    f = 0;
    j = 0;
  }
  return 0;
}
Problem p00221 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int m, n;
  string in;
  for (;;) {
    cin >> m >> n;
    if (m == 0 && n == 0)
      break;
    vector<bool> islive(m, true);
    int nokori = m, at = 0;
    for (int ix = 1; ix <= n; ix++) {
      cin >> in;
      for (; at < m; at++) {
        if (islive[at])
          break;
      }
      if (at == m) {
        for (at = 0; at < m; at++) {
          if (islive[at])
            break;
        }
      }
      if (nokori > 1) {
        bool is = false;
        if (ix % 3 == 0 && ix % 5 == 0) {
          if (in != string("FizzBuzz"))
            is = true;
        } else if (ix % 3 == 0) {
          if (in != string("Fizz"))
            is = true;
        } else if (ix % 5 == 0) {
          if (in != string("Buzz"))
            is = true;
        } else {
          stringstream ss;
          ss << ix;
          if (in != ss.str()) {
            is = true;
          }
        }
        if (is) {
          nokori--;
          islive[at] = false;
        }
        at++;
      }
    }
    vector<int> out;
    for (int i = 0; i < m; i++) {
      if (islive[i])
        out.push_back(i + 1);
    }
    cout << out[0];
    for (int i = 1; i < out.size(); i++) {
      cout << " " << out[i];
    }
    cout << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
#include <sstream>
#include <vector>
using namespace std;
int main() {
  int p, n;
  for (;;) {
    cin >> p >> n;
    if (p == 0 && n == 0)
      break;
    vector<bool> ar(p, true);
    int now = 0;
    for (int i = 1; i <= n; i++) {
      string ins;
      cin >> ins;
      bool isf = false;
      if (i % 3 == 0 && i % 5 == 0) {
        if (ins != "FizzBuzz")
          isf = true;
      } else if (i % 3 == 0) {
        if (ins != "Fizz")
          isf = true;
      } else if (i % 5 == 0) {
        if (ins != "Buzz")
          isf = true;
      } else {
        stringstream ss;
        ss << i;
        if (ins != ss.str()) {
          isf = true;
        }
      }
      if (isf) {
        ar[now] = false;
      }
      now++;
      for (;; now++) {
        if (now == p)
          now = 0;
        if (ar[now])
          break;
      }
    }
    for (int i = 0; i < p; i++) {
      if (ar[i])
        cout << i + 1 << ' ';
    }
    cout << endl;
  }
}
Problem p00221 (C++) — buggy submission, verdict: Runtime Error

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

string ansFizzBuzz(int n) {
  string result;
  if (n % 15 == 0) {
    result = "FizzBuzz";
  } else if (n % 3 == 0) {
    result = "Fizz";
  } else if (n % 5 == 0) {
    result = "Buzz";
  } else {
    stringstream ss;
    ss << n;
    ss >> result;
  }
  return result;
}

int main() {
  while (true) {
    int m, n;
    cin >> m >> n;
    if ((m | n) == 0) {
      break;
    }
    vector<int> players(m);
    for (int i = 0; i < m; i++) {
      players[i] = i + 1;
    }
    vector<string> lines(n);
    for (int i = 0; i < n; i++) {
      cin >> lines[i];
    }
    int pos = 0;
    for (int i = 0; i < n; i++) {
      if (players.size() <= 1) {
        break;
      }
      if (lines[i] != ansFizzBuzz(i + 1)) {
        players.erase(players.begin() + pos);
      } else {
        pos++;
      }
      pos = pos % players.size();
    }
    string result;
    for (vector<int>::iterator it = players.begin(); it != players.end();
         it++) {
      stringstream ss;
      ss << *it;
      result += " " + ss.str();
    }
    result.erase(0, 1);
    cout << result << endl;
  }
}

Error: 0

Fixed submission:

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

string ansFizzBuzz(int n) {
  string result;
  if (n % 15 == 0) {
    result = "FizzBuzz";
  } else if (n % 3 == 0) {
    result = "Fizz";
  } else if (n % 5 == 0) {
    result = "Buzz";
  } else {
    stringstream ss;
    ss << n;
    ss >> result;
  }
  return result;
}

int main() {
  while (true) {
    int m, n;
    cin >> m >> n;
    if ((m | n) == 0) {
      break;
    }
    vector<int> players(m);
    for (int i = 0; i < m; i++) {
      players[i] = i + 1;
    }
    int pos = 0;
    for (int i = 0; i < n; i++) {
      string str;
      cin >> str;
      if (str != ansFizzBuzz(i + 1)) {
        players.erase(players.begin() + pos);
      } else {
        pos++;
      }
      pos = pos % players.size();
    }
    string result;
    for (vector<int>::iterator it = players.begin(); it != players.end();
         it++) {
      stringstream ss;
      ss << (*it);
      string temp;
      ss >> temp;
      result += " " + temp;
    }
    result.erase(0, 1);
    cout << result << endl;
  }
}
Problem p00221 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>

using namespace std;

int main(int argc, char const *argv[]) {
  int m, n;
  const string Fizz("Fizz"), Buzz("Buzz"), FizzBuzz("FizzBuzz");
  string str;
  vector<int> player;
  vector<int>::iterator it;

  while (cin >> m >> n && m) {
    getchar();
    player.clear();
    for (int i = 1; i <= m; i++)
      player.push_back(i);

    it = player.begin();
    for (int i = 1; i <= n; i++) {
      if (it == player.end())
        it = player.begin();
      getline(cin, str);
      if (player.size() == 1)
        continue;

      if (!(i % 15)) {
        if (FizzBuzz != str) {
          it = player.erase(it);
          continue;
        }
      } else if (!(i % 3)) {
        if (Fizz != str) {
          it = player.erase(it);
          continue;
        }
      } else if (!(i % 5)) {
        if (Buzz != str) {
          it = player.erase(it);
          continue;
        }
      } else {
        int j;
        for (j = 0; j < str.size(); j++) {
          if (str[j] > '9' || str[j] < '0') {
            break;
          }
        }
        if (j == str.size()) {
          if (atoi(str.c_str()) != i) {
            it = player.erase(it);
            continue;
          }
        } else {
          it = player.erase(it);
          continue;
        }
      }
      it++;
    }

    for (int i = 0; i < player.size(); i++) {
      cout << ((i == 0) ? "" : " ") << player[i];
    }
    cout << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

using namespace std;

int main(int argc, char const *argv[]) {
  const string Fizz("Fizz"), Buzz("Buzz"), FizzBuzz("FizzBuzz");
  string str;
  int m, n;
  bool user[1001] = {false};

  while (cin >> m >> n && m) {
    getchar();
    for (int i = 0; i <= 1000; i++)
      user[i] = false;

    int i = 1;
    int count = 0;
    for (int j = 1; j <= n; j++) {
      if (count == m)
        return 0;
      while (user[i] == true) {
        i++;
        if (i == m)
          i = 1;
      }

      if (i > m)
        i = 1;
      getline(cin, str);
      if (count == m - 1)
        continue;
      if (!(j % 15)) {
        if (str != FizzBuzz)
          user[i] = true;
      } else if (!(j % 3)) {
        if (str != Fizz)
          user[i] = true;
      } else if (!(j % 5)) {
        if (str != Buzz)
          user[i] = true;
      } else {
        for (int k = 0; k < str.length(); k++)
          if (str[k] < '0' || str[k] > '9')
            user[k] = true;
        if (user[i] != true)
          if (atoi(str.c_str()) != j)
            user[i] = true;
      }

      if (user[i] == true)
        count++;
      i++;
    }

    int hoge = 0;
    for (i = 1; i <= m; i++) {
      if (user[i] == false) {
        cout << (hoge == 0 ? "" : " ") << i;
        hoge++;
      }
    }
    cout << endl;
  }
  return 0;
}
Problem p00221 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <sstream>
#include <vector>
using namespace std;

bool fizzBuzzCheck(int n, string s) {
  if (n % 15 == 0)
    return (s == "FizzBuzz");
  if (n % 3 == 0)
    return (s == "Fizz");
  if (n % 5 == 0)
    return (s == "Buzz");

  for (int i = 0; i < s.length(); i++)
    if (s[i] < '0' || s[i] > '9')
      return false;

  return (atoi(s.c_str()) == n);
}

int main() {
  int n, m;
  string s;

  while (scanf("%d %d\\n", &m, &n), m) {

    vector<int> rem(m);
    for (int i = 0; i < m; i++) {
      rem[i] = i + 1;
    }
    int c = 0;
    for (int i = 1; i <= n; i++) {
      getline(cin, s);
      if (rem.size() == 1)
        continue;
      if (!fizzBuzzCheck(i, s)) {
        rem.erase(remove(rem.begin(), rem.end(), rem[c]), rem.end());
      } else {
        c++;
      }
      c %= rem.size();
    }
    for (int i = 0; i < rem.size(); i++) {
      cout << (i ? " " : "") << rem[i];
    }
    cout << endl;
  }
}

Error: WA

Fixed submission:

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

using namespace std;

int main(int argc, char const *argv[]) {
  string Fizz("Fizz"), Buzz("Buzz"), FizzBuzz("FizzBuzz");
  string str;
  int m, n;
  bool user[1001] = {false};

  while (cin >> m >> n && m && n) {
    for (int i = 0; i <= 1000; i++)
      user[i] = false;

    int i = 1;
    int count = 0;
    for (int j = 1; j <= n; j++) {
      if (i > m)
        i = 1;
      getline(cin, str);
      if (user[i] == true) {
        i++;
        continue;
      }
      if (count == m - 1)
        continue;
      if (!(j % 3) && !(j % 5)) {
        if (str != FizzBuzz)
          user[i] = true;
      } else if (!(j % 3)) {
        if (str != Fizz)
          user[i] = true;
      } else if (!(j % 5)) {
        if (str != Buzz)
          user[i] = true;
      } else {
        for (int k = 0; k < str.length(); k++)
          if (str[k] < '0' || str[k] > '9')
            user[k] = true;
        if (user[i] != true)
          if (atoi(str.c_str()) != j)
            user[i] = true;
      }

      if (user[i] == true)
        count++;
      i++;
    }

    for (i = 1; i <= m; i++) {
      if (user[i] == false) {
        ++count;
        cout << i << (m - count ? " " : "");
      }
    }
    cout << endl;
  }
  return 0;
}
Problem p00221 (C++) — buggy submission, verdict: Time Limit Exceeded

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

string fizzbuzz(int i) {
  stringstream sst;
  sst << i;
  if (i % 15 == 0)
    return "FizzBuzz";
  else if (i % 5 == 0)
    return "Buzz";
  else if (i % 3 == 0)
    return "Fizz";
  else
    return sst.str();
}

int main() {
  int m, n;
  while (cin >> m >> n) {
    if (m == 0 && n == 0)
      break;
    string str;
    bool *player = new bool[m];
    int check = m;
    for (int i = 0; i < m; i++) {
      player[i] = true;
    }

    int pos = 0;
    for (int i = 0; i < n; i++) {
      cin >> str;
      if (check != 1 && str != fizzbuzz(i + 1)) {
        player[pos] = false;
        check--;
      }
      pos++;
      pos %= m;
      if (check != 1) {
        while (player[pos] != true) {
          pos++;
          pos %= m;
        }
      }
    }

    bool flag = false;
    for (int i = 0; i < m; i++) {
      if (player[i] == true) {
        if (flag == true)
          cout << " ";
        cout << i + 1;
        flag = true;
      }
    }
    cout << endl;
    delete[] player;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <sstream>
#include <string>
using namespace std;

bool player[1000];
void init() {
  for (int i = 0; i < 1000; i++) {
    player[i] = true;
  }
}
// iツづーツ偲ウツつッツ偲ヲツづづ陛板つキ
string fizzbuzz(int i) {
  if (i % 15 == 0)
    return "FizzBuzz";
  else if (i % 5 == 0)
    return "Buzz";
  else if (i % 3 == 0)
    return "Fizz";
  else {
    stringstream sst;
    sst << i;
    return sst.str();
  }
}
int main() {
  int m, n;
  string str;
  while (cin >> m >> n) {
    if (m == 0 && n == 0)
      break;
    init();
    int game = 1;
    int playercount = 0;
    for (int i = 0; i < n; i++) {
      cin >> str;
      if (str != fizzbuzz(game))
        player[playercount] = false;
      playercount++;
      playercount %= m;
      while (player[playercount] == false) {
        playercount++;
        playercount %= m;
      }

      game++;
    }
    bool flag = false;
    for (int i = 0; i < m; i++) {
      if (flag)
        cout << " ";
      if (player[i] == true) {
        cout << i + 1;
        flag = true;
      }
    }
    cout << endl;
  }
  return 0;
}
Problem p00221 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <iostream>
#include <string>
using namespace std;

int parse(string a) {
  int b = 0;
  for (char c : a)
    b = b * 10 + c - 48;
  return b;
}
int main() {
  int a, b;
  while (cin >> a >> b, a | b) {
    bool c[1000]{};
    int sum = 0;
    int T = a;
    string p[10000];
    getline(cin, p[0]);
    for (int i = 0; i < b; i++)
      getline(cin, p[i]);
    for (int d = 1; d <= b; d++, sum++) {
      while (c[sum % a])
        sum++;
      string k = p[d - 1];
      bool B = false;
      if (d % 3 == 0) {
        if (d % 5 == 0) {
          if (k != "FizzBuzz")
            B = true;
        } else {
          if (k != "Fizz")
            B = true;
        }
      } else if (d % 5 == 0) {
        if (k != "Buzz")
          B = true;
      } else {
        if (parse(k) != d)
          B = true;
      }
      if (B) {
        T--;
        c[sum % a] = true;
      }
      if (T == 1)
        break;
    }
    int w = 0;
    for (int i = 0; i < a; i++) {
      if (!c[i]) {
        if (w)
          cout << " ";
        w++;
        cout << i + 1;
      }
    }
    cout << endl;
  }
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>
#include <string>
using namespace std;

int parse(string a) {
  int b = 0;
  for (char c : a)
    b = b * 10 + c - 48;
  return b;
}
int main() {
  int a, b;
  while (cin >> a >> b, a | b) {
    bool c[1000]{};
    int sum = 0;
    int T = a;
    string k;
    getline(cin, k);
    for (int d = 1; d <= b; d++, sum++) {
      while (c[sum % a])
        sum++;
      getline(cin, k);
      bool B = false;
      if (d % 3 == 0) {
        if (d % 5 == 0) {
          if (k != "FizzBuzz")
            B = true;
        } else {
          if (k != "Fizz")
            B = true;
        }
      } else if (d % 5 == 0) {
        if (k != "Buzz")
          B = true;
      } else {
        if (parse(k) != d)
          B = true;
      }
      if (B) {
        T--;
        c[sum % a] = true;
      }
      if (T == 1)
        break;
    }
    int w = 0;
    for (int i = 0; i < a; i++) {
      if (!c[i]) {
        if (w)
          cout << " ";
        w++;
        cout << i + 1;
      }
    }
    cout << endl;
  }
}
Problem p00221 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int m, n;
  while (cin >> m >> n, m) {
    bool live[1010];
    int idx = 1, cnt = m;
    memset(live, true, sizeof live);

    for (int i = 1; i <= n; ++i) {
      string s;
      cin >> s;

      if (cnt != 1) {
        string str = to_string(i);
        if (i % 15 == 0)
          str = "FizzBuzz";
        else if (i % 3 == 0)
          str = "Fizz";
        else if (i % 5 == 0)
          str = "Buzz";

        if (str != s) {
          live[idx] = false;
          cnt--;
        }

        idx++;
        if (idx == m + 1)
          idx = 1;
        while (!live[idx]) {
          idx++;
          if (idx == m + 1)
            idx = 1;
        }
      }
    }

    vector<int> ans;
    for (int i = 1; i <= m; ++i) {
      if (live[i])
        ans.push_back(i);
    }
    for (int i = 0; i < ans.size(); ++i) {
      cout << ans[i] << (i + 1 == ans.size() ? "\\n" : " ");
    }
  }
}


Error: TLE

Fixed submission:

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

int main() {
  int m, n;
  while (cin >> m >> n, m) {
    bool live[1010];
    int idx = 1, cnt = m;
    memset(live, true, sizeof live);
    for (int i = 1; i <= n; ++i) {
      string s;
      cin >> s;

      bool f = true;
      if (i % 3 == 0 && i % 5 == 0) {
        if (s != "FizzBuzz")
          f = false;
      } else if (i % 3 == 0) {
        if (s != "Fizz")
          f = false;
      } else if (i % 5 == 0) {
        if (s != "Buzz")
          f = false;
      } else {
        if (s != to_string(i))
          f = false;
      }

      if (!f) {
        live[idx] = false;
        cnt--;
      }

      if (cnt == 1)
        break;

      idx++;
      if (idx == m + 1)
        idx = 1;
      while (!live[idx]) {
        idx++;
        if (idx == m + 1)
          idx = 1;
      }
    }

    vector<int> ans;
    for (int i = 1; i <= m; ++i) {
      if (live[i])
        ans.push_back(i);
    }
    for (int i = 0; i < ans.size(); ++i) {
      cout << ans[i] << (i + 1 == ans.size() ? "\\n" : " ");
    }
  }
}