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

#include <algorithm>
#include <iostream>
#include <set>
#include <string>

using namespace std;

int main() {
  std::ios_base::sync_with_stdio(false);

  string cmd, key;
  int n;
  set<string> dic;

  cin >> n;

  while (cin >> cmd >> key) {
    if (cmd == "insert") {
      dic.insert(key);
    } else if (cmd == "find") {
      if (dic.find(key) != dic.end()) {
        cout << "yes" << endl;
      } else {
        cout << "no" << endl;
      }
    }
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
  int n;
  string inst, word;
  vector<string> dic;
  vector<string>::iterator it;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> inst >> word;
    if (inst[0] == 'i') {
      dic.push_back(word);
    } else {
      if (find(dic.begin(), dic.end(), word) != dic.end())
        cout << "yes" << endl;
      else
        cout << "no" << endl;
    }
  }
  return 0;
}
Problem p02269 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <list>
#include <queue>
#include <stack>
#include <string.h>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <map>
#include <math.h>

using namespace std;

int main() {
  int n;
  char str[10], com[13];
  map<string, bool> m;
  cin >> n;
  for (int i = 0; i < n; i++) {
    scanf("%s%s", com, str);
    if (com[0] == 'i')
      m[string(str)] = true;
    else {
      if (m[string(str)])
        cout << "yes";
      else
        cout << "no";
      cout << endl;
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <list>
#include <queue>
#include <stack>
#include <string.h>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <map>
#include <math.h>

using namespace std;

int main() {
  int n;
  string str, com;
  map<string, bool> m;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> com >> str;
    if (com[0] == 'i')
      m[str] = true;
    else {
      if (m[str])
        cout << "yes";
      else
        cout << "no";
      cout << endl;
    }
  }
  return 0;
}
Problem p02269 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#define SIZE 33554432
char Key[128];
int Hash;
char *c;
#define HASH(A)                                                                \\
  c = A;                                                                       \\
  Hash = 1;                                                                    \\
  while (*c) {                                                                 \\
    Hash <<= 2;                                                                \\
    Hash += Key[*c];                                                           \\
    ++c;                                                                       \\
  }
using namespace std;
int main() {
  // freopen("in.txt", "r", stdin);
  // freopen("out.txt", "w", stdout);
  Key['A'] = 0;
  Key['C'] = 1;
  Key['G'] = 2;
  Key['T'] = 3;
  bool *dic = new bool[SIZE];
  fill(dic, dic + SIZE, false);
  int n;
  std::scanf("%d\\n", &n);
  char str[21];
  for (int i = 0; i < n; ++i) {
    fgets(str, 21, stdin);
    if (str[0] == 'i') {
      HASH(str + 7)
      dic[Hash] = true;
    } else {
      HASH(str + 5)
      puts((dic[Hash] ? "yes" : "no"));
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

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

// TLE, why!?

const int m = 9973;
int init = 0;
long long T[m] = {init};

int h1(int key) { return key % m; }

int h2(int key) { return 1 + (key % (m - 1)); }

int h(int key, int i) { return (h1(key) + i * h2(key)) % m; }

void insert(long long key) {
  for (int i = 0; i <= m; ++i) {
    int j = h(key, i);
    if (T[j] == init) {
      T[j] = key;
      break;
    } else {
      continue;
    }
  }
}

bool find(long long key) {
  for (int i = 0; i <= m; ++i) {
    int j = h(key, i);
    if (T[j] == key) {
      return true;
    } else if (T[j] == init || i == m) {
      return false;
    }
  }
}

long long stokey(string a) {
  int pow = 1;
  int sum = 0;
  int p;
  for (int i = 0; i < a.size(); ++i) {
    if (a[i] == 'A') {
      p = 1;
    } else if (a[i] == 'C') {
      p = 2;
    } else if (a[i] == 'G') {
      p = 3;
    } else if (a[i] == 'T') {
      p = 4;
    }
    sum += pow * p;
    pow *= 5;
  }
  return sum;
}

int main() {
  // cin,cout accelerate
  ios::sync_with_stdio(false);
  cin.tie(0);

  chrono::system_clock::time_point start, end; // ?????? auto ??§???
  start = chrono::system_clock::now();

  int n;
  cin >> n;
  string cmd, chars;
  for (int i = 0; i < n; ++i) {
    cin >> cmd;
    if (cmd[0] == 'i') {
      cin >> chars;
      insert(stokey(chars));
    } else if (cmd[0] == 'f') {
      cin >> chars;
      if (find(stokey(chars))) {
        cout << "yes" << endl;
      } else {
        cout << "no" << endl;
      }
    }
  }

  end = std::chrono::system_clock::now(); // ?¨???¬????????????
  double elapsed =
      std::chrono::duration_cast<std::chrono::milliseconds>(end - start)
          .count();

  // cout<<elapsed<<endl;
}
Problem p02269 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <list>
#include <stdio.h>
#include <string>
using namespace std;
#define N 22369620
#define X 50
struct hush {
  list<int> a;
};
int main(void) {
  int n, sum = 0, x, f[1000000] = {0}, cou = 0;
  char str[7], acgt[13];
  hush H[N / X];
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    sum = 0;
    scanf("%s", str);
    scanf("%s", acgt);
    for (int i = 0, k = 1; acgt[i] != '\\0' && i < 12; i++, k *= 4) {
      switch (acgt[i]) {
      case 'A':
        x = 1;
        break;
      case 'C':
        x = 2;
        break;
      case 'G':
        x = 3;
        break;
      case 'T':
        x = 4;
        break;
      }
      sum += x * k;
    }
    if (str[0] == 'i') {
      H[sum / X].a.push_back(sum % X);
    } else {
      list<int>::iterator p = H[sum / X].a.begin();
      for (; p != H[sum / X].a.end(); ++p) {
        if ((sum % X) == *p) {
          f[cou] = 1;
        }
      }
      cou++;
    }
  }
  for (int i = 0; i < cou; i++) {
    if (f[i])
      printf("yes\\n");
    else
      printf("no\\n");
  }
}

Error: -11

Fixed submission:

#include <iostream>
#include <list>
#include <stdio.h>
#include <string>
using namespace std;
#define N 22369620
#define X 25
struct hush {
  list<int> a;
};
int main(void) {
  int n, sum = 0, x, f[1000000] = {0}, cou = 0;
  char str[7], acgt[13];
  hush H[N / X];
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    sum = 0;
    scanf("%s", str);
    scanf("%s", acgt);
    for (int i = 0, k = 1; acgt[i] != '\\0' && i < 12; i++, k *= 4) {
      switch (acgt[i]) {
      case 'A':
        x = 1;
        break;
      case 'C':
        x = 2;
        break;
      case 'G':
        x = 3;
        break;
      case 'T':
        x = 4;
        break;
      }
      sum += x * k;
    }
    if (str[0] == 'i') {
      H[sum / X].a.push_back(sum % X);
    } else {
      list<int>::iterator p = H[sum / X].a.begin();
      for (; p != H[sum / X].a.end(); ++p) {
        if ((sum % X) == *p) {
          f[cou] = 1;
        }
      }
      cou++;
    }
  }
  for (int i = 0; i < cou; i++) {
    if (f[i])
      printf("yes\\n");
    else
      printf("no\\n");
  }
}
Problem p02269 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <iostream>
#define _USE_MATH_DEFINES
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 999999999
#define atcoder 1e9 + 7

using namespace std;

int main() {

  set<string> s;
  string s1, s2;
  int n;

  cin >> n;

  REP(i, n) {
    cin >> s1 >> s2;
    if (s1 == "insert")
      s.insert(s2);
    else if (s1 == "find") {
      if (s.find(s2) != s.end())
        cout << "yes" << endl;
      else
        cout << "no" << endl;
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
#define _USE_MATH_DEFINES
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 999999999
#define atcoder 1e9 + 7

using namespace std;

int main() {

  string s1, s2;
  vector<string> str;
  int n;
  bool jud = false;

  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> s1 >> s2;
    if (s1 == "insert")
      str.push_back(s2);
    else if (s1 == "find") {
      if (find(str.begin(), str.end(), s2) != str.end())
        jud = true;
      if (jud)
        cout << "yes" << endl;
      else
        cout << "no" << endl;
    }
    jud = false;
  }

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

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

int main() {
  typedef unordered_set<string> set_t;
  set_t A;
  int n;
  string s, t;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s >> t;
    if (s == "insert") {
      A.insert(t);
    } else if (s == "find") {
      bool find = A.count(t);
      cout << (find ? "yes" : "no") << endl;
    }
  }
}

Error: TLE

Fixed submission:

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

int main() {
  typedef set<string> set_t;
  set_t A;
  int n;
  string s, t;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s >> t;
    if (s == "insert") {
      A.insert(t);
    } else if (s == "find") {
      bool find = A.count(t);
      cout << (find ? "yes" : "no") << endl;
    }
  }
}
Problem p02269 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <string>

#define M 1046527

int dic[M] = {0};

int toInt(std::string str) {
  int ret, i, pow;
  char ch;
  ret = 0;
  pow = 1;
  for (i = 0; i < (int)str.size(); i++) {
    ch = str[i];
    if (ch == 'A')
      ret += pow;
    else if (ch == 'C')
      ret += pow * 2;
    else if (ch == 'G')
      ret += pow * 3;
    else
      ret += pow * 4;
    pow *= 5;
  }
  // std::cout << ret << std::endl;
  return ret;
}

int hash1(int key) { return key % M; }

int hash2(int key) { return (1 + key % (M - 1)); }

void insert(std::string str) {
  int i, key, h, h1, h2;
  i = 0;
  key = toInt(str);
  h1 = hash1(key);
  h2 = hash2(key);
  while (1) {
    h = (h1 + i * h2) % M;
    // std::cout << h << std::endl;
    if (dic[h] == 0) {
      dic[h] = key + 1;
      break;
    } else if (dic[h] == key + 1) {
      break;
    } else
      i++;
  }
}

bool find(std::string str) {
  int i, h1, h2, key, h;
  bool flag;
  i = 0;
  key = toInt(str);
  h1 = hash1(key);
  h2 = hash2(key);
  while (1) {
    h = (h1 + i * h2) % M;
    if (dic[h] == 0) {
      flag = false;
      break;
    } else if (dic[h] == key + 1) {
      flag = true;
      break;
    } else
      i++;
  }
  return flag;
}

int main() {
  int i, n;
  std::string op, str;
  std::cin >> n;
  for (i = 0; i < n; i++) {
    std::cin >> op >> str;
    if (op == "insert") {
      insert(str);
    } else {
      if (find(str))
        std::cout << "yes" << std::endl;
      else
        std::cout << "no" << std::endl;
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <string>

#define M 1046527

int dic[M] = {0};

int toInt(std::string str) {
  int ret, i, pow;
  char ch;
  ret = 0;
  pow = 1;
  for (i = 0; i < (int)str.size(); i++) {
    ch = str[i];
    if (ch == 'A')
      ret += pow;
    else if (ch == 'C')
      ret += pow * 2;
    else if (ch == 'G')
      ret += pow * 3;
    else
      ret += pow * 4;
    pow *= 5;
  }
  // std::cout << ret << std::endl;
  return ret;
}

int hash1(int key) { return key % M; }

int hash2(int key) { return (1 + key & (M - 1)); }

void insert(std::string str) {
  int i, key, h, h1, h2;
  i = 0;
  key = toInt(str);
  h1 = hash1(key);
  h2 = hash2(key);
  while (1) {
    h = h1 + i * h2;
    // std::cout << h << std::endl;
    if (dic[h] == 0) {
      dic[h] = key + 1;
      break;
    } else if (dic[h] == key + 1) {
      break;
    } else
      i++;
  }
}

bool find(std::string str) {
  int i, h1, h2;
  long long key, h;
  bool flag;
  i = 0;
  key = toInt(str);
  h1 = hash1(key);
  h2 = hash2(key);
  while (1) {
    h = h1 + i * h2;
    if (dic[h] == 0) {
      flag = false;
      break;
    } else if (dic[h] == key + 1) {
      flag = true;
      break;
    } else
      i++;
  }
  return flag;
}

int main() {
  int i, n;
  std::string op, str;
  std::cin >> n;
  for (i = 0; i < n; i++) {
    std::cin >> op >> str;
    if (op == "insert") {
      insert(str);
    } else {
      if (find(str))
        std::cout << "yes" << std::endl;
      else
        std::cout << "no" << std::endl;
    }
  }
  return 0;
}
Problem p02269 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define M 1046527
using namespace std;
long long h1(long long key) { return key % M; }
long long h2(long long key) { return 1 + (key % (M - 1)); }
long long getNum(char c) {
  if (c == 'A')
    return 1;
  if (c == 'C')
    return 2;
  if (c == 'G')
    return 3;
  if (c == 'T')
    return 4;
  return 0;
}
long long getValue(char *s) {
  long long i = 0, value = 0;
  while (s[i]) {
    value = value * 10 + getNum(s[i]);
    i++;
  }
  return value;
}
char s[1046527][13], word[13], order[10];
long long n, key, value;
int main() {
  cin >> n;
  for (long long i = 0; i < 1000006; i++)
    s[i][0] = 0;
  for (long long i = 0; i < n; i++) {
    scanf("%s %s", order, word);
    value = getValue(word);
    if (order[0] == 'i') {
      long long k = 0;
      while (true) {
        key = (h1(value) + k * h2(value)) % M;
        if (strcmp(s[key], word) == 0) {
          break;
        } else if (strlen(s[key]) == 0) {
          strcpy(s[key], word);
          break;
        }
        k++;
      }
    } else {
      long long k = 0;
      while (true) {
        key = (h1(value) + k * h2(value)) % M;
        if (strcmp(s[key], word) == 0) {
          cout << "yes\\n";
          break;
        } else if (strlen(s[key]) == 0) {
          cout << "no\\n";
          break;
        }
        k++;
      }
    }
  }

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define M 1046527
using namespace std;
long long h1(long long key) { return key % M; }
long long h2(long long key) { return 1 + (key % (M - 1)); }
long long getNum(char c) {
  if (c == 'A')
    return 1;
  if (c == 'C')
    return 2;
  if (c == 'G')
    return 3;
  if (c == 'T')
    return 4;
  return 0;
}
long long getValue(char *s) {
  long long i = 0, value = 0;
  while (s[i]) {
    value = value * 10 + getNum(s[i]);
    i++;
  }
  return value;
}
char s[1000006][13], word[13], order[10];
long long n, key, value;
int main() {
  cin >> n;
  for (long long i = 0; i < 1000006; i++)
    s[i][0] = 0;
  for (long long i = 0; i < n; i++) {
    scanf("%s %s", order, word);
    value = getValue(word);
    if (order[0] == 'i') {
      long long k = 0;
      while (true) {
        key = (h1(value) + k * h2(value)) % M;
        if (strcmp(s[key], word) == 0) {
          break;
        } else if (strlen(s[key]) == 0) {
          strcpy(s[key], word);
          break;
        }
        k++;
      }
    } else {
      long long k = 0;
      while (true) {
        key = (h1(value) + k * h2(value)) % M;
        if (strcmp(s[key], word) == 0) {
          cout << "yes\\n";
          break;
        } else if (strlen(s[key]) == 0) {
          cout << "no\\n";
          break;
        }
        k++;
      }
    }
  }

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

#include <algorithm>
#include <iostream>
#include <set>
#include <string>

using namespace std;

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

  int n = 0;
  cin >> n;
  cin.ignore();

  set<string> dic;

  for (int i = 0; i < n; i++) {
    string buf;
    getline(cin, buf);
    if (buf[0] == 'i') {
      dic.insert(buf.substr(7));
    } else {
      if (dic.find(buf.substr(5)) != dic.end()) {
        cout << "yes" << endl;
      } else {
        cout << "no" << endl;
      }
    }
  }
  return 0;
}

Error: -6
terminate called after throwing an instance of 'std::out_of_range'
  what():  basic_string::substr: __pos (which is 5) > this->size() (which is 0)


Fixed submission:

#include <algorithm>
#include <iostream>
#include <set>
#include <vector>

using namespace std;

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

  int n = 0;
  cin >> n;

  set<string> dic;

  for (int i = 0; i < n; i++) {
    string buf;
    getline(cin, buf);
    if (buf[0] == 'i') {
      dic.insert(buf.substr(7));
    } else {
      if (dic.find(buf.substr(5)) != dic.end()) {
        cout << "yes" << '\\n';
      } else {
        cout << "no" << '\\n';
      }
    }
  }
  return 0;
}
Problem p02269 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <set>
#include <string>
#include <vector>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  set<string> dict;

  for (int i = 0; i < N; ++i) {
    string command;
    string val;

    cin >> command;
    cin >> val;

    if (command[0] == 'i') {
      // insert
      dict.insert(val);
    } else {
      // find
      if (dict.find(val) != dict.end()) {
        cout << "yes" << endl;
      } else {
        cout << "no" << endl;
      }
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <set>
#include <string>
#include <vector>

using namespace std;

int main() {
  int N;
  cin >> N;
  set<string> dict;

  for (int i = 0; i < N; ++i) {
    string command;
    string val;

    cin >> command;
    cin >> val;

    if (command[0] == 'i') {
      // insert
      dict.insert(val);
    } else {
      // find
      if (dict.find(val) != dict.end()) {
        cout << "yes" << endl;
      } else {
        cout << "no" << endl;
      }
    }
  }

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

#include <bits/stdc++.h>
#define rep(i, j, k) for (int i = (int)j; i < (int)k; i++)
#define itrep(x) for (auto it = (x).begin(); it != (x).end(); it++)
#define Sort(x) sort((x).begin(), (x).end())
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define vi vector<int>
#define INF (int)1e9
#define INFL 1e18
#define MOD 1000000007
#define pb push_back
#define MP make_pair
#define PI 3.1415926535
typedef long long int ll;
typedef std::pair<int, int> P;
int D = 1;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};

using namespace std;

int main() {
  int n;
  cin >> n;
  map<string, int> mp;
  rep(i, 0, n) {
    string s, t;
    cin >> s >> t;
    if (s == "insert")
      mp[t]++;
    else if (s == "find") {
      if (mp[t] == 0)
        cout << "no" << endl;
      else
        cout << "yes" << endl;
    }
  }

  return 0;
}


Error: TLE

Fixed submission:

#define _CRT_SECURE_NO_WARNINGS

#include <algorithm>
#include <cmath>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define rep(i, p, n) for (int i = (int)p; i < (int)n; i++)
#define repp(i, p, n) for (int i = (int)p; i >= (int)n; i--)
#define Sort(x) sort(x.begin(), x.end())
#define PSort(x) sort(begin(x), end(x), pairCompare)
#define ll long long
#define INF 2000000000
#define pb push_back
#define mp make_pair
#define PI 3.14159265358979

using namespace std;

int main() {
  vector<string> v;
  int n;
  cin >> n;
  rep(i, 0, n) {
    string s;
    cin >> s;
    if (s == "insert") {
      string ss;
      cin >> ss;
      v.pb(ss);
    } else {
      string ss;
      cin >> ss;
      if (find(v.begin(), v.end(), ss) != v.end()) {
        cout << "yes" << endl;
      } else
        cout << "no" << endl;
    }
  }

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

#include <iostream>
#include <set>
#include <string>
using namespace std;
int main() {
  int n;
  string a, b;
  set<string> st;
  cin >> n;
  while (n--) {
    cin >> a >> b;
    if (a == "insert")
      st.insert(b);
    if (a == "find") {
      if (st.find(b) == st.end())
        cout << "no" << endl;
      else
        cout << "yes" << endl;
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  string a, b, str[13];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    if (a == "insert") {
      str[b.size()] += b;
      str[b.size()] += " ";
    }
    if (a == "find") {
      if (str[b.size()].find(b) == string::npos) {
        cout << "no" << endl;
      } else
        cout << "yes" << endl;
    }
  }
  return 0;
}