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

#include <cstdio>
#include <iostream>
#define REP(i, a, b) for (i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
#define MOD1 1000000007;
#define MOD2 1000007
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
/* ここからが本編 */
/*  */

ull pow(ull x, ull n) {
  ull res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * x;
    x = x * x;
    n >>= 1;
  }
  return res;
}
int dic_op(char str[14]) {
  int j;
  long long f = 1;
  long long g = 0;
  for (j = 0;; j++) {
    if (str[j] == 'A')
      g += f * 1;
    else if (str[j] == 'C')
      g += f * 2;
    else if (str[j] == 'G')
      g += f * 3;
    else if (str[j] == 'T')
      g += f * 4;
    else
      break;
    f *= 5;
  }
  return g;
}

int main() {
  int i, j, k, l;
  int n;
  long ans = 0;
  static char dic[10000000];
  char opstr[7];
  char str[13];
  cin >> n;
  for (i = 0; i < n; i++) {
    scanf("%s %s", opstr, str);
    if (opstr[0] == 'i') {
      dic[dic_op(str)] = 1;
    } else if (opstr[0] == 'f') {
      if (dic[dic_op(str)] == 1)
        puts("yes");
      else
        puts("no");
      j++;
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <cstdio>
#include <iostream>
#define REP(i, a, b) for (i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
#define MOD1 1000000007;
#define MOD2 1000007
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
/* ここからが本編 */
/*  */

ull pow(ull x, ull n) {
  ull res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * x;
    x = x * x;
    n >>= 1;
  }
  return res;
}
int dic_op(char str[14]) {
  int j;
  long long f = 1;
  long long g = 0;
  for (j = 0;; j++) {
    if (str[j] == 'A')
      g += f * 1;
    else if (str[j] == 'C')
      g += f * 2;
    else if (str[j] == 'G')
      g += f * 3;
    else if (str[j] == 'T')
      g += f * 4;
    else
      break;
    f *= 5;
  }
  return g;
}

int main() {
  int i, j, k, l;
  int n;
  long ans = 0;
  static char dic[7000000];
  char opstr[7];
  char str[13];
  cin >> n;
  for (i = 0; i < n; i++) {
    scanf("%s %s", opstr, str);
    if (opstr[0] == 'i') {
      dic[dic_op(str)] = 1;
    } else if (opstr[0] == 'f') {
      if (dic[dic_op(str)] == 1)
        puts("yes");
      else
        puts("no");
      j++;
    }
  }
  return 0;
}
Problem p02269 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define M 1006000
#define L 14

char H[M][L]; /* Hash Table */

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;
}

/* convert a string into an integer value */
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 (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) {
      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 <iostream>
#include <list>
#include <string>
using namespace std;

list<string> hashTable[1000000];

int getKey(string str) {
  int key = 0;
  for (int i = 0; i < str.size(); i++) {
    key += str[i] * (i + 1);
  }
  return key;
}

int getHash(string str) { return getKey(str) % 1000000; }

void insert(string str) {
  int hash = getHash(str);
  hashTable[hash].push_back(str);
}

bool isExist(string str) {
  int hash = getHash(str);
  list<string>::iterator it;
  for (it = hashTable[hash].begin(); it != hashTable[hash].end(); it++) {
    if (!(*it).compare(str))
      return true;
  }
  return false;
}

int main() {
  string str, command;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> command >> str;
    if (!command.compare("insert")) {
      insert(str);
    } else {
      (isExist(str)) ? cout << "yes" << endl : cout << "no" << endl;
    }
  }
  return 0;
}
Problem p02269 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
// #include "toollib.h"
// #include "puzzle.h"
#define INT_MAX 2147483647
#define Loop(i, n) for (int i = 0; i < (int)n; i++)
#pragma warning(disable : 4018)
#pragma warning(disable : 4244)
#pragma warning(disable : 4996)

using namespace std;
typedef long long int lint;

//***** Main Program *****

int main() {
  map<string, bool> mp;
  int n;
  cin >> n;
  Loop(i, n) {
    char query[10];
    string word;
    scanf("%s", query);
    cin >> word;
    if (query[0] == 'i') {
      mp[word] = true;
    } else {
      if (mp[word])
        printf("yes\\n");
      else
        printf("no\\n");
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
// #include "toollib.h"
// #include "puzzle.h"
#define INT_MAX 2147483647
#define Loop(i, n) for (int i = 0; i < (int)n; i++)
#pragma warning(disable : 4018)
#pragma warning(disable : 4244)
#pragma warning(disable : 4996)

using namespace std;
typedef long long int lint;

//***** Main Program *****

int main() {
  map<string, bool> mp;
  int n;
  cin >> n;
  Loop(i, n) {
    string query, word;
    cin >> query >> word;
    if (query == "insert") {
      mp[word] = true;
    } else {
      if (mp[word])
        cout << "yes" << endl;
      else
        cout << "no" << endl;
    }
  }
  return 0;
}
Problem p02269 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
// #include "toollib.h"
// #include "puzzle.h"
#define INT_MAX 2147483647
#define Loop(i, n) for (int i = 0; i < (int)n; i++)
#pragma warning(disable : 4018)
#pragma warning(disable : 4244)
#pragma warning(disable : 4996)

using namespace std;
typedef long long int lint;

//***** Main Program *****

vector<bool> dictionary((int)pow(4, 12), false);

int main() {
  int n;
  cin >> n;
  Loop(i, n) {
    char cquery[10], cword[15];
    scanf("%s %s", cquery, cword);
    lint j = 0, k = 1, key = 0;
    while (cword[j] != '\\0') {
      if (cword[j] == 'A')
        key += 1 * k;
      else if (cword[j] == 'T')
        key += 2 * k;
      else if (cword[j] == 'G')
        key += 3 * k;
      else
        key += 4 * k;
      k *= 4;
      j++;
    }
    if (cquery[0] == 'i') {
      dictionary[key - 1] = true;
    } else {
      bool judge = dictionary[key - 1];
      if (judge)
        printf("yes\\n");
      else
        printf("no\\n");
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
// #include "toollib.h"
// #include "puzzle.h"
#define INT_MAX 2147483647
#define Loop(i, n) for (int i = 0; i < (int)n; i++)
#pragma warning(disable : 4018)
#pragma warning(disable : 4244)
#pragma warning(disable : 4996)

using namespace std;
typedef long long int lint;

//***** Main Program *****

vector<bool> dictionary((int)pow(4, 10), false);

int main() {
  int n;
  cin >> n;
  Loop(i, n) {
    char cquery[10], cword[15];
    scanf("%s %s", cquery, cword);
    lint j = 0, k = 1, key = 0;
    while (cword[j] != '\\0') {
      if (cword[j] == 'A')
        key += 1 * k;
      else if (cword[j] == 'T')
        key += 2 * k;
      else if (cword[j] == 'G')
        key += 3 * k;
      else
        key += 4 * k;
      k *= 4;
      j++;
    }
    if (cquery[0] == 'i') {
      dictionary[key - 1] = true;
    } else {
      bool judge = dictionary[key - 1];
      if (judge)
        printf("yes\\n");
      else
        printf("no\\n");
    }
  }
  return 0;
}
Problem p02269 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define L 14
#define M 1046527
char H[M][L];

// getChar??
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;
}

// getKey???
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 sum;
}

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

// findのとき
int find(char str[]) {
  long long key, h, i;
  key = getKey(str); // 文字列を数値に変換
  for (i = 0;; i++) {
    h = (h1(key) + i * h2(key)) % M; // 衝突がなければh1のみ
    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, h, i;
  key = getKey(str); // 文字列を数値に変換
  for (i = 0;; i++) {
    h = (h1(key) + i * h2(key)) % M; // 衝突がなければh1のみ
    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 n;
  char str[L], com[9]; // comは"insert"or"find"のいずれか
  for (int i = 0; i < M; i++) {
    H[i][0] = '\\0';
  }
  scanf("%d", &n);

  for (int 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");
      }
    }
  }
}


Error: TLE

Fixed submission:

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

int main() {
  int n;
  cin >> n;
  vector<string> A;
  vector<string> C;
  vector<string> G;
  vector<string> T;
  string b, c;
  string ans;
  for (int i = 0; i < n; i++) {
    cin >> b >> c;
    if (b == "insert") {
      if (c.at(0) == 'A')
        A.push_back(c);
      if (c.at(0) == 'C')
        C.push_back(c);
      if (c.at(0) == 'G')
        G.push_back(c);
      if (c.at(0) == 'T')
        T.push_back(c);
    }
    if (b == "find") {
      ans = "no";
      if (c.at(0) == 'A') {
        for (int i = 0; i < A.size(); i++) {
          if (c == A.at(i)) {
            ans = "yes";
          }
        }
        cout << ans << endl;
      }
      if (c.at(0) == 'C') {
        for (int i = 0; i < C.size(); i++) {
          if (c == C.at(i)) {
            ans = "yes";
          }
        }
        cout << ans << endl;
      }
      if (c.at(0) == 'G') {
        for (int i = 0; i < G.size(); i++) {
          if (c == G.at(i)) {
            ans = "yes";
          }
        }
        cout << ans << endl;
      }
      if (c.at(0) == 'T') {
        for (int i = 0; i < T.size(); i++) {
          if (c == T.at(i)) {
            ans = "yes";
          }
        }
        cout << ans << endl;
      }
    }
  }
}
Problem p02269 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <numeric>
#include <set>
#include <string>

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

using namespace std;
int n;
string str;
string mess;
set<string> ma;
int main() {
  cin >> n;
  rep(i, n) {
    cin >> str >> mess;
    if (str[0] == 'i') {
      ma.insert(mess);
    } else {
      if (ma.find(mess) != ma.end()) {
        printf("yes\\n");
      } else {
        printf("no\\n");
      }
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <numeric>
#include <set>
#include <string>

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

using namespace std;
int n;
string str;
string mess;
set<string> ma;
int main() {
  cin >> n;
  rep(i, n) {
    cin >> str >> mess;
    if (str[0] == 'i') {
      ma.insert(mess);
    } else {
      if (ma.find(mess) != ma.end()) {
        cout << "yes" << endl;
      } else {
        cout << "no" << endl;
      }
    }
  }
  return 0;
}
Problem p02269 (C++) — buggy submission, verdict: Time Limit Exceeded

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

typedef pair<int, int> P;

#define MAX_S 12

P MakeNum(const char *);

bool Check[(1 << (MAX_S * 2)) - 1][MAX_S + 1];

int main() {
  char ch[MAX_S + 1];
  int n;
  scanf("%d", &n);
  while (n--) {
    scanf("%s", ch);
    if (ch[0] == 'i') {
      scanf("%s", ch);
      P p = MakeNum(ch);
      Check[p.first][p.second] = true;
    } else {
      scanf("%s", ch);
      P p = MakeNum(ch);
      if (Check[p.first][p.second])
        printf("yes\\n");
      else
        printf("no\\n");
    }
  }
  return 0;
}

P MakeNum(const char *ch) {
  int res = 0;
  int i = 0;
  for (; ch[i] != '\\0'; ++i) {
    int num;
    switch (ch[i]) {
    case 'A':
      num = 0;
      break;
    case 'C':
      num = 1;
      break;
    case 'G':
      num = 2;
      break;
    case 'T':
      num = 3;
      break;
    };
    res |= num << (i * 2);
  }
  --i;
  return P(res, i);
}

Error: TLE

Fixed submission:

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

int main() {
  set<string> dic;
  int n;
  cin >> n;
  while (n--) {
    string str;
    cin >> str;
    if (str == "insert") {
      cin >> str;
      dic.insert(str);
    } else {
      cin >> str;
      if (dic.find(str) != dic.end())
        cout << "yes" << endl;
      else
        cout << "no" << endl;
    }
  }
  return 0;
}
Problem p02269 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n;
  cin >> n;
  map<string, bool> T;
  for (int i = 0; i < n; i++) {
    char str[10];
    char C[13];
    cin >> str >> C;
    if (str[0] == 'i') {
      T[string(C)] = true;
    } else {
      if (T.find(C) != T.end()) {
        cout << "yes" << endl;
      } else
        cout << "no" << endl;
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <stdio.h>
#include <string>
#define INTERVAL 100
using namespace std;

int hash1(string S);
int HASH(int h, int i);
int StoI(string S);
bool Search(string *TABLE, string str, int i);

int main() {
  int n;
  scanf("%d", &n);
  char str1[7];
  char str2[13];
  string *table;
  table = new string[16 * 16 * 16 * INTERVAL];
  for (int i = 0; i < n; i++) {
    scanf("%s", str1);
    scanf("%s", str2);
    if (str1[0] == 'i') {
      int l = 0;
      while (true) {
        int temp = HASH(hash1(str2), l);
        if (table[temp].empty()) {
          table[temp] = str2;
          break;
        } else if (table[temp] == str2)
          break;
        else {
          l++;
        }
      }
    } else {
      while (true) {
        if (Search(table, str2, 0)) {
          cout << "yes" << endl;
          break;
        } else {
          cout << "no" << endl;
          break;
        }
      }
    }
  }
  delete[] table;
  return 0;
}

int hash1(string S) {
  int k = StoI(S);
  return k % INTERVAL;
}
int HASH(int h1, int i) { return h1 + INTERVAL * i; }
bool Search(string *TABLE, string str, int i) {
  int temp = HASH(hash1(str), i);
  if (TABLE[temp] == str)
    return true;
  else if (TABLE[temp].empty())
    return false;
  else
    return Search(TABLE, str, i + 1);
}
int StoI(string S) {
  int n = S.size();
  int k = 0;
  for (int i = 0; i < n; i++) {
    if (S[i] == 'A')
      k += 1;
    else if (S[i] == 'C')
      k += 2;
    else if (S[i] == 'G')
      k += 3;
    else
      k += 4;
  }
  return k;
}
Problem p02269 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define Lim 9999991
#define Jmp 100003

int dic[Lim];

int toint(string s) {
  int ret = 0;
  for (int i = 0; i < s.size(); ++i) {
    ret *= 5;
    switch (s[i]) {
    case 'A':
      ret += 1;
      break;
    case 'T':
      ret += 2;
      break;
    case 'G':
      ret += 3;
      break;
    case 'C':
      ret += 4;
      break;
    }
  }
  return ret;
}

void push(string s) {
  int a = toint(s);
  int i = a;
  while (true) {
    if (!dic[i]) {
      dic[i] = a;
      return;
    }
    i = (i + Jmp) % Lim;
  }
}

int find(string s) {
  int a = toint(s);
  int i = a;
  while (true) {
    if (!dic[i]) {
      return 0;
    }
    if (dic[i] == a) {
      return 1;
    }
    i = (i + Jmp) % Lim;
  }
}

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    string s, t;
    cin >> s >> t;
    if (s == "insert") {
      push(t);
    } else {
      if (find(t)) {
        printf("yes\\n");
      } else {
        printf("no\\n");
      }
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define Lim 9999991
#define Jmp 100003

long long dic[Lim];

long long toint(string s) {
  long long ret = 0;
  for (int i = 0; i < s.size(); ++i) {
    ret <<= 3;
    switch (s[i]) {
    case 'A':
      ret += 1;
      break;
    case 'T':
      ret += 2;
      break;
    case 'G':
      ret += 3;
      break;
    case 'C':
      ret += 4;
      break;
    }
  }
  return ret;
}

void push(string s) {
  int a = toint(s);
  int i = a;
  while (true) {
    if (!dic[i]) {
      dic[i] = a;
      return;
    }
    i += Jmp;
  }
}

int find(string s) {
  int a = toint(s);
  int i = a;
  while (true) {
    if (!dic[i]) {
      return 0;
    }
    if (dic[i] == a) {
      return 1;
    }
    i += Jmp;
  }
}

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    string s, t;
    cin >> s >> t;
    if (s == "insert") {
      push(t);
    } else {
      if (find(t)) {
        printf("yes\\n");
      } else {
        printf("no\\n");
      }
    }
  }
  return 0;
}
Problem p02269 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define Lim 9999991
#define Jmp 1000003

int dic[Lim];

int toint(string s) {
  int ret = 0;
  for (int i = 0; i < s.size(); ++i) {
    ret *= 5;
    switch (s[i]) {
    case 'A':
      ret += 1;
      break;
    case 'T':
      ret += 2;
      break;
    case 'G':
      ret += 3;
      break;
    case 'C':
      ret += 4;
      break;
    }
  }
  return ret;
}

void push(string s) {
  int a = toint(s);
  int i = a % Lim;
  while (true) {
    if (!dic[i]) {
      dic[i] = a;
      return;
    }
    i = (i + Jmp) % Lim;
  }
}

int find(string s) {
  int a = toint(s);
  int i = a % Lim;
  while (true) {
    if (!dic[i]) {
      return 0;
    }
    if (dic[i] == a) {
      return 1;
    }
    i = (i + Jmp) % Lim;
  }
}

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    string s, t;
    cin >> s >> t;
    if (s == "insert") {
      push(t);
    } else {
      if (find(t)) {
        printf("yes\\n");
      } else {
        printf("no\\n");
      }
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define Lim 9999991
#define Jmp 13

int dic[Lim];

int toint(string s) {
  int ret = 0;
  for (int i = 0; i < s.size(); ++i) {
    ret *= 5;
    switch (s[i]) {
    case 'A':
      ret += 1;
      break;
    case 'T':
      ret += 2;
      break;
    case 'G':
      ret += 3;
      break;
    case 'C':
      ret += 4;
      break;
    }
  }
  return ret;
}

void push(string s) {
  int a = toint(s);
  int i = a % Lim;
  while (true) {
    if (!dic[i]) {
      dic[i] = a;
      return;
    }
    i = (i + Jmp) % Lim;
  }
}

int find(string s) {
  int a = toint(s);
  int i = a % Lim;
  while (true) {
    if (!dic[i]) {
      return 0;
    }
    if (dic[i] == a) {
      return 1;
    }
    i = (i + Jmp) % Lim;
  }
}

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    string s, t;
    cin >> s >> t;
    if (s == "insert") {
      push(t);
    } else {
      if (find(t)) {
        printf("yes\\n");
      } else {
        printf("no\\n");
      }
    }
  }
  return 0;
}
Problem p02269 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

int main() {
  int n;
  scanf("%d", &n);
  set<string> strs;
  for (int i = 0; i < n; i++) {
    char cmd[10], str[15];
    scanf("%s %s", cmd, str);
    if (cmd[0] == 'i') {
      strs.insert(str);
    } else {
      if (strs.count(str)) {
        printf("yes\\n");
      } else {
        printf("no\\n");
      }
    }
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

int main() {
  int n;
  cin >> n;
  set<string> strs;
  for (int i = 0; i < n; i++) {
    string cmd, str;
    cin >> cmd >> str;
    if (cmd[0] == 'i') {
      strs.insert(str);
    } else {
      if (strs.count(str)) {
        cout << "yes" << endl;
      } else {
        cout << "no" << endl;
      }
    }
  }
}