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

#include <cstdio>
#include <cstdlib>
#include <cstring>
#define N 1046527

using namespace std;
char hs[N][14];

int dd(char d) {
  switch (d) {
  case 'A':
    return 1;

  case 'C':
    return 2;

  case 'T':
    return 3;

  case 'G':
    return 4;
  }
  return 0;
}

int ids(char *c) {
  int id = 0;
  int pos = 0, p = 1;
  while (1) {

    if (c[pos] == '\\0')
      break;
    id += p * dd(c[pos]);
    pos++;
    p *= 5;
  }
  return id;
}

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

void insert(char *c) {
  int i = 0;
  int key = ids(c);
  while (true) {
    int j = h(key, i);
    if (hs[j][0] == '?') {
      strcpy(hs[j], c);
      return;
    }
    i = i + 1;
  }
}

bool search(char *c) {
  int i = 0;
  int key = ids(c);
  while (true) {
    int j = h(key, i);
    if (strcmp(hs[j], c) == 0) {
      return true;
    } else if (hs[j][0] == '?' || i >= N) {
      return false;
    }
    i = i + 1;
  }
}

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < N; i++)
    hs[i][0] = '?';
  char in[9];
  char inn[14];
  for (int i = 0; i < n; i++) {
    scanf(" %s %s", in, inn);
    if (in[0] == 'i') {
      insert(inn);
    } else {
      if (search(inn)) {
        printf("yes\\n");
      } else {
        printf("no\\n");
      }
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <cstdio>
#include <cstdlib>
#include <cstring>
#define N 1047379

using namespace std;
char hs[N][14];

int dd(char d) {
  switch (d) {
  case 'A':
    return 2;

  case 'C':
    return 3;

  case 'T':
    return 4;

  case 'G':
    return 1;
  }
  return 1;
}

int ids(char *c) {
  int id = 1;
  int pos = 0;
  while (1) {

    if (c[pos] == '\\0')
      break;
    id = id * dd(c[pos]) % N;
    pos++;
    id *= 5;
  }
  return id;
}

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

int insert(char *c) {
  int i = 0;
  int key = ids(c);
  while (true) {
    int j = h(key, i);
    if (hs[j][0] == '?') {
      strcpy(hs[j], c);
      return j;
    } else {
      i = i + 1;
    }
  }
}

bool search(char *c) {
  int i = 0;
  int key = ids(c);
  while (true) {
    int j = h(key, i);
    if (strcmp(hs[j], c) == 0) {
      return true;
    } else if (hs[j][0] == '?' || i >= N) {
      return false;
    }
    i = i + 1;
  }
}

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < N; i++)
    hs[i][0] = '?';
  char in[9];
  char inn[14];
  for (int i = 0; i < n; i++) {
    scanf(" %s %s", in, inn);
    if (in[0] == 'i') {
      insert(inn);
    } else {
      if (search(inn)) {
        printf("yes\\n");
      } else {
        printf("no\\n");
      }
    }
  }
  return 0;
}
Problem p02269 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#define TABLE_SIZE 22369620

class Dic {
  bool *table;
  int converter(char *str);

public:
  Dic() {
    table = (bool *)malloc(sizeof(bool) * TABLE_SIZE);
    memset(table, 0, sizeof(bool) * TABLE_SIZE);
  }
  void insert(char *str) { table[converter(str)] = true; }
  bool find(char *str) { return table[converter(str)]; }
};

int Dic::converter(char *str) {
  int key = 0;
  int len = strlen(str);
  for (int i = 0; i < len; i++) {
    switch (str[i]) {
    case 'A':
      key += pow(4, i);
      break;
    case 'C':
      key += 2 * pow(4, i);
      break;
    case 'G':
      key += 3 * pow(4, i);
      break;
    case 'T':
      key += 4 * pow(4, i);
      break;
    default:
      break;
    }
  }
  return key - 1;
}

int main() {
  int i, n;
  char str[13];
  int bs = 0;
  Dic d;
  scanf("%d", &n);
  bool ans[n];
  for (i = 0; i < n; i++) {
    scanf("%s", str);
    if (!strcmp(str, "insert")) {
      scanf("%s", str);
      d.insert(str);
    } else if (!strcmp(str, "find")) {
      scanf("%s", str);
      ans[bs] = d.find(str);
      bs++;
    }
  }
  for (i = 0; i < bs; i++) {
    if (ans[i])
      printf("yes\\n");
    else
      printf("no\\n");
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <cstdio>
#include <cstdlib>
#include <cstring>

class dict {
  int size;
  char (*p)[13];

public:
  dict(int n) {
    size = 0;
    p = new char[n][13];
  }
  void insert(char *str) {
    strcpy(p[size], str);
    size++;
  }
  bool find(char *str) {
    for (int i = 0; i < size; i++) {
      if (!strcmp(p[i], str))
        return true;
    }
    return false;
  }
};

int main() {
  int i, n;
  int nf = 0;
  char str[13];
  scanf("%d", &n);
  dict d(n);
  bool b[n];
  for (i = 0; i < n; i++) {
    scanf("%s", str);
    if (!strcmp(str, "insert")) {
      scanf("%s", str);
      d.insert(str);
    } else if (!strcmp(str, "find")) {
      scanf("%s", str);
      b[nf] = d.find(str);
      nf++;
    } else
      return -1;
  }
  for (i = 0; i < nf; i++) {
    if (b[i])
      printf("yes\\n");
    else
      printf("no\\n");
  }
  return 0;
}
Problem p02269 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
#include <string.h>
int n, r[128], t[13];
bool used[22370000];
char com[8], s[14];
int main() {
  scanf("%d", &n);
  r[65] = 1, r[67] = 2, r[71] = 3;
  for (int i = 2; i < 13; i++)
    t[i] = t[i - 1] + (1 << (2 * i - 2));
  for (int i = 0; i < n; i++) {
    scanf("%s %s", com, s);
    int h = 0, l = strlen(s);
    for (int j = 0; j < l; j++)
      h = h * 4 + r[s[j]];
    if (com[0] == 105)
      used[h + t[l]] = true;
    else
      puts(used[h + t[l]] ? "yes" : "no");
  }
}

Error: 0

Fixed submission:

#include <stdio.h>
#include <string.h>
int n, r[128], t[13];
bool used[22370000];
char com[8], s[14];
int main() {
  scanf("%d", &n);
  r[65] = 1, r[67] = 2, r[71] = 3;
  for (int i = 2; i < 12; i++)
    t[i] = t[i - 1] + 1 << (2 * i - 2);
  for (int i = 0; i < n; i++) {
    scanf("%s %s", com, s);
    int h = 0, l = strlen(s);
    for (int j = 0; j < l; j++)
      h = h * 4 + r[s[j]];
    if (com[0] == 105)
      used[h + t[l]] = true;
    else
      puts(used[h + t[l]] ? "yes" : "no");
  }
}
Problem p02269 (C++) — buggy submission, verdict: Time Limit Exceeded

#define _CRT_SECURE_NO_WARNINGS 1

#include <cmath>
#include <cstdio>
#include <string>
#include <vector>

using namespace std;

#define MAX_LETTERS 12

const char Alphabet[4] = {'A', 'C', 'G', 'T'};

int cipher(string S) {
  int Ans = 0;

  for (string::size_type i = 0; i < S.size(); i++) {
    for (int j = 0; j < 4; j++) {
      if (Alphabet[j] == S[i]) {
        Ans +=
            pow<int>(sizeof(Alphabet) / sizeof(const char), S.size() - i - 1) *
            j;
      }
    }
  }

  return Ans;
}

int main() {
  vector<vector<bool>> D;

  unsigned n;

  for (int i = 0; i <= MAX_LETTERS; i++) {
    D.push_back(vector<bool>(
        pow<unsigned>(sizeof(Alphabet) / sizeof(const char), i), false));
  }

  scanf("%d", &n);

  vector<string> W;

  vector<bool> F(n);

  for (vector<bool>::size_type i = 0; i < n; i++) {
    char S1[20], S2[20];

    string S3, S4;

    scanf("%s%s", &S1, &S2);

    S3 = S1;
    S4 = S2;

    if (S3 == "find") {
      F[i] = true;
    }

    W.push_back(S4);
  }

  for (vector<string>::size_type i = 0; i < n; i++) {
    if (F[i] == false) {
      D[W[i].size()][cipher(W[i])] = true;
    } else {
      printf("%s\\n", (D[W[i].size()][cipher(W[i])] ? "yes" : "no"));
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

#define MAX_LETTERS 12

const char Alphabet[4] = {'A', 'C', 'G', 'T'};

int cipher(string S) {
  int Ans = 0;

  for (string::size_type i = 0; i < S.size(); i++) {
    for (int j = 0; j < 4; j++) {
      if (Alphabet[j] == S[i]) {
        Ans +=
            pow<int>(sizeof(Alphabet) / sizeof(const char), S.size() - i - 1) *
            j;
      }
    }
  }

  return Ans;
}

int main() {
  vector<vector<bool>> D;

  unsigned n;

  for (int i = 0; i <= MAX_LETTERS; i++) {
    D.push_back(vector<bool>(
        pow<unsigned>(sizeof(Alphabet) / sizeof(const char), i), false));
  }

  cin >> n;

  vector<string> W;

  vector<bool> F(n);

  for (vector<bool>::size_type i = 0; i < n; i++) {
    string S1, S2;

    cin >> S1 >> S2;

    if (S1 == "find") {
      F[i] = true;
    }

    W.push_back(S2);
  }

  for (vector<string>::size_type i = 0; i < n; i++) {
    if (F[i] == false) {
      D[W[i].size()][cipher(W[i])] = true;
    } else {
      cout << (D[W[i].size()][cipher(W[i])] ? "yes" : "no") << endl;
    }
  }

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

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

#define M 1046527
#define NIL (-1)
#define L 14

char H[M][L];

// 文字から数値に変換
int getChar(char ch) {
  if (ch == 'A')
    return 1;
  else if (ch == 'C')
    return 2;
  else if (ch == 'G')
    return 3;
  else if (ch == 'T')
    return 4;
  else
    return 0;
}

// 文字列から数値へ変換してkeyを生成する
long long getKey(char str[]) {
  long long sum = 0, p = 1, i;
  for (i = 0; i < strlen(str); i++) {
    sum += p * getChar(str[i]);
    p *= 5;
  }
  return sum;
}

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

int find(char str[]) {
  long long key, i, h;
  key = getKey(str);
  for (i = 0;; i++) {
    h = (h1(key) + i + h2(key)) % M;
    if (strcmp(H[h], str) == 0)
      return 1;
    else if (strlen(H[h]) == 0)
      return 0;
  }
  return 0;
}

int insert(char str[]) {
  long long key, i, h;
  key = getKey(str);
  for (i = 0;; i++) {
    h = (h1(key) + i + h2(key)) % M;
    if (strcmp(H[h], str) == 0)
      return 1;
    else if (strlen(H[h]) == 0) {
      strcpy(H[h], str);
      return 0;
    }
  }
  return 0;
}

int main() {
  int i, n, h;
  char str[L], com[9];
  for (i = 0; i < M; i++)
    H[i][0] = '\\0';
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%s %s", com, str);

    if (com[0] == 'i') {
      insert(str);
    } else {
      if (find(str)) {
        printf("yes\\n");
      } else {
        printf("no\\n");
      }
    }
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <stdio.h>
#include <string>
#include <vector>
using namespace std;

vector<string> D;

int main() {
  int n;
  char o[7], v[14];
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%s %s", o, v);
    if (o[0] == 'i') {
      D.push_back(v);
    } else if (o[0] == 'f') {
      int j = 0;
      for (string s : D) {
        if (s == v)
          printf("yes\\n");
      }
      printf("no\\n");
    }
  }

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

#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;
int main() {
  int n;
  cin >> n;
  typedef unordered_set<string> set_t;
  set_t A;
  string s;
  while (n > 0) {
    cin >> s;
    if (s == "insert") {
      cin >> s;
      A.insert(s);
    } else if (s == "find") {
      cin >> s;
      int m = A.count(s);
      if (m == 1)
        cout << "yes" << endl;
      else
        cout << "no" << endl;
    }
    n = n - 1;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
int main() {
  int n;
  cin >> n;
  typedef set<string> set_t;
  set_t A;
  string s;
  while (n > 0) {
    cin >> s;
    if (s == "insert") {
      cin >> s;
      A.insert(s);
    } else if (s == "find") {
      cin >> s;
      int m = A.count(s);
      if (m == 1)
        cout << "yes" << endl;
      else
        cout << "no" << endl;
    }
    n = n - 1;
  }
}
Problem p02269 (C++) — buggy submission, verdict: Time Limit Exceeded

#include "math.h"
#include <iostream>
#include <string>

using namespace std;

int n;

bool *data;

int getChar(char a) {
  if (a == 'A')
    return 1;
  else if (a == 'C')
    return 2;
  else if (a == 'G')
    return 3;
  else if (a == 'T')
    return 4;
  else
    return 0;
}

int getKey(string str) {
  int res = 0;

  int l = str.size();
  int p = 1;
  for (int i = 0; i < l; i++) {
    int v = getChar(str[i]);
    res += p * v;
    p *= 5;
  }
  return res;
}

void insert(string str) {
  int key = getKey(str);
  data[key] = true;
}

bool find(string str) {
  int key = getKey(str);
  return data[key];
}

int main() {
  int v = pow(5, 12);
  data = new bool[v];

  cin >> n;
  for (int i = 0; i < n; i++) {
    string cmd, str;

    cin >> cmd >> str;

    if (cmd == "insert") {
      insert(str);
    } else if (cmd == "find") {
      if (find(str)) {
        cout << "yes" << endl;
      } else {
        cout << "no" << endl;
      }
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include "math.h"
#include <iostream>
#include <string>

using namespace std;

int n;

bool *data;

int getChar(char a) {
  if (a == 'A')
    return 1;
  else if (a == 'C')
    return 2;
  else if (a == 'G')
    return 3;
  else if (a == 'T')
    return 4;
  else
    return 0;
}

int getKey(string str) {
  int res = 0;

  int l = str.size();
  for (int i = 0; i < l; i++) {
    int v = getChar(str[i]);
    res += v * pow(5, l - i - 1);
  }
  return res;
}

void insert(string str) {
  int key = getKey(str);
  data[key] = true;
}

bool find(string str) {
  int key = getKey(str);
  return data[key];
}

int main() {
  int v = pow(5, 12);
  data = new bool[v];

  cin >> n;
  for (int i = 0; i < n; i++) {
    string cmd, str;

    cin >> cmd >> str;

    if (cmd == "insert") {
      insert(str);
    } else if (cmd == "find") {
      if (find(str)) {
        cout << "yes" << endl;
      } else {
        cout << "no" << endl;
      }
    }
  }
  return 0;
}
Problem p02269 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <typeinfo>
#include <vector>
#define PI 3.14159265359
#define INF 99999999;
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(n) rep(i, n)
#define EPS 1e-10
typedef long long ll;
using namespace std;
typedef pair<int, int> P;

double distanceAB(double xa, double ya, double xb, double yb);
void trace(int A[], int N);

/*
class Target
{
public:
        vector <string> draw(int n)
        {

        }
};
*/

int main() {
  int n;
  char str[10], com[13];
  map<string, bool> T;

  cin >> n;
  REP(n) {
    scanf("%s%s", com, str);
    if (com[0] == 'i') {
      T[string(str)] = true;
    } else {
      if (T[string(str)])
        printf("yes\\n");
      else
        printf("no\\n");
    }
  }

  return 0;
}

void trace(int A[], int N) {
  REP(N) {
    if (i > 0)
      cout << " ";
    cout << A[i];
  }
  cout << endl;
}

double distanceAB(double xa, double ya, double xb, double yb) {
  return sqrt((xb - xa) * (xb - xa) + (yb - ya) * (yb - ya));
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <typeinfo>
#include <vector>
#define PI 3.14159265359
#define INF 99999999;
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(n) rep(i, n)
#define EPS 1e-10
typedef long long ll;
using namespace std;
typedef pair<int, int> P;

double distanceAB(double xa, double ya, double xb, double yb);
void trace(int A[], int N);

/*
class Target
{
public:
        vector <string> draw(int n)
        {

        }
};
*/

int main() {
  int n;
  char str[10], com[13];
  map<string, bool> T;

  cin >> n;
  REP(n) {
    cin >> com >> str;
    if (com[0] == 'i') {
      T[string(str)] = true;
    } else {
      if (T[string(str)])
        printf("yes\\n");
      else
        printf("no\\n");
    }
  }

  return 0;
}

void trace(int A[], int N) {
  REP(N) {
    if (i > 0)
      cout << " ";
    cout << A[i];
  }
  cout << endl;
}

double distanceAB(double xa, double ya, double xb, double yb) {
  return sqrt((xb - xa) * (xb - xa) + (yb - ya) * (yb - ya));
}
Problem p02269 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <iostream>
#include <set>
#include <string>

using namespace std;

int main() {
  int N;
  string S1, S2;

  cin >> N;

  set<string> dictionary;

  for (int i = 0; i < N; i++) {
    cin >> S1 >> S2;

    if (S1[0] == 'i') {
      dictionary.insert(S2);
    } else {
      if (dictionary.find(S2) != dictionary.end()) {
        printf("yes\\n");
      } else {
        printf("no\\n");
      }
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

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

using namespace std;

int main() {
  int N;
  string S1, S2;

  cin >> N;

  set<string> dictionary;

  for (int i = 0; i < N; i++) {
    cin >> S1 >> S2;

    if (S1[0] == 'i') {
      dictionary.insert(S2);
    } else {
      if (dictionary.find(S2) != dictionary.end()) {
        cout << "yes" << endl;
      } else {
        cout << "no" << endl;
      }
    }
  }

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

#include <iostream>
#include <map>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  map<string, int> m;
  int q;
  cin >> q;
  while (q--) {
    string command, str;
    cin >> command >> str;
    if (command == "insert") {
      m[str] = 1;
    } else if (command == "find") {
      map<string, int>::iterator itr = m.find(str);
      if (itr == m.end())
        cout << "no" << endl;
      else
        cout << "yes" << endl;
    }
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int n;
  vector<string> v;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string str, word;
    cin >> str >> word;
    if (str == "insert")
      v.push_back(word);
    else if (str == "find") {
      vector<string>::iterator it;
      it = find(v.begin(), v.end(), word);
      if (it != v.end())
        cout << "yes\\n";
      else
        cout << "no\\n";
    }
  }
  return 0;
}
Problem p02269 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <string>
#include <vector>
#define M 1000000
std::vector<std::vector<std::string>> dic(M);
int hash(char ch) {
  if (ch == 'A')
    return 1;
  if (ch == 'C')
    return 2;
  if (ch == 'G')
    return 3;
  if (ch == 'T')
    return 4;
  return 0;
}

long long key(std::string str) {
  long long v = 0;
  int b = 1, n = str.size();
  for (int i = 0; i < n; i++) {
    v += b * (hash(str[i]));
    b *= 5;
  }
  return v % M;
}

int find(std::string str) {
  std::vector<std::string> s;
  s = dic[key(str)];
  int n = s.size();
  for (int i = 0; i < n; i++) {
    if (s[i] == str)
      return 1;
  }
  return 0;
}

void insert(std::string str) { dic[key(str)].push_back(str); }

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


Error: 0

Fixed submission:

#include <iostream>
#include <string>
#include <vector>
#define M 1000000
std::vector<std::vector<std::string>> dic(M);
int hash(char ch) {
  if (ch == 'A')
    return 1;
  if (ch == 'C')
    return 2;
  if (ch == 'G')
    return 3;
  if (ch == 'T')
    return 4;
  return 0;
}

long long key(std::string str) {
  long long v = 0;
  int b = 1, n = str.size();
  for (int i = 0; i < n; i++) {
    v += b * (hash(str[i]));
    b *= 5;
  }
  return v;
}

int find(std::string str) {
  std::vector<std::string> s;
  s = dic[key(str)];
  int n = s.size();
  for (int i = 0; i < n; i++) {
    if (s[i] == str)
      return 1;
  }
  return 0;
}

void insert(std::string str) { dic[key(str)].push_back(str); }

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

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

int main() {
  int n, size;
  string cmd, str;
  set<string> dic;
  queue<string> yn;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> cmd >> str;
    if (cmd == "insert")
      dic.insert(str);
    else {
      if (dic.count(str))
        yn.push("yes");
      else
        yn.push("no");
    }
  }
  size = yn.size();
  for (int i = 0; i < size; i++) {
    cout << yn.front() << endl;
    yn.pop();
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <list>
#include <queue>
using namespace std;

int main() {
  int n, size, l, r, m, p;
  string cmd, str;
  list<string> dic;
  queue<string> yn;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> cmd >> str;
    size = dic.size();
    if (size == 0) {
      if (cmd == "insert")
        dic.push_front(str);
      else
        yn.push("no");
    } else {
      list<string>::iterator itdic = dic.begin();
      l = 0;
      r = size - 1;
      p = -1;
      while (l <= r && p == -1) {
        m = (l + r) / 2;
        advance(itdic, m);
        if (*itdic == str) {
          if (cmd == "insert") {
            dic.insert(itdic, str);
            p = 1;
          } else {
            yn.push("yes");
            p = 1;
          }
        } else if (str < *itdic)
          r = m - 1;
        else
          l = m + 1;
        itdic = dic.begin();
      }
      if (p == -1) {
        if (cmd == "insert") {
          advance(itdic, l);
          dic.insert(itdic, str);
        } else
          yn.push("no");
      }
    }
  }
  size = yn.size();
  for (int i = 0; i < size; i++) {
    cout << yn.front() << endl;
    yn.pop();
  }
  return 0;
}
Problem p02269 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <set>
#include <string>

int main() {
  int n = 0;
  scanf("%d", &n);
  std::string cmd, str;
  char buff[100];
  std::set<std::string> dict;
  for (int i = 0; i < n; i++) {
    scanf("%s", buff);
    cmd = buff;
    scanf("%s", buff);
    str = buff;
    if (cmd[0] == 'i') {
      dict.insert(str);
    } else {
      if (dict.find(str) != dict.end()) {
        printf("yes\\n");
      } else {
        printf("no\\n");
      }
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <cstring>

#define M 1046527
#define NIL (-1)
#define L 14

char H[M][L] = {'\\0'};

int getChar(char ch) {
  if (ch == 'A') {
    return 1;
  } else if (ch == 'C') {
    return 2;
  } else if (ch == 'G') {
    return 3;
  } else if (ch == 'T') {
    return 4;
  } else {
    return 0;
  }
}

long long getKey(char *str) {
  long long sum = 0, p = 1;
  for (int i = 0; i < strlen(str); i++) {
    sum += p * (getChar(str[i]));
    p *= 5;
  }
  return 0;
}

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

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

int insert(char *str) {
  long long key;
  key = getKey(str); // str to index
  for (int i = 0;; i++) {
    int h = (h1(key) + i * h2(key)) % M;
    if (strcmp(H[h], str) == 0) {
      return 1;
    } else if (strlen(H[h]) == 0) {
      strcpy(H[h], str);
      return 0;
    }
  }
  return 0;
}

bool find(char *str) {
  long long key = getKey(str);
  int h = 0;
  for (int i = 0;; i++) {
    h = (h1(key) + i * h2(key)) % M;
    if (strcmp(H[h], str) == 0) {
      return 1;
    } else if (strlen(H[h]) == 0) {
      return 0;
    }
  }
  return 0;
}

int hash(char *key) { return 0; }

int main() {
  int n = 0;
  scanf("%d", &n);
  char cmd[9] = {0}, str[L] = {0};

  for (int i = 0; i < n; i++) {
    scanf("%s %s", cmd, str);
    if (cmd[0] == 'i') {
      insert(str);
    } else {
      if (find(str)) {
        printf("yes\\n");
      } else {
        printf("no\\n");
      }
    }
  }

  return 0;
}