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() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  set<string> dict;
  int n;
  cin >> n;
  for (int i; i < n; ++i) {
    string c, s;
    cin >> c >> s;
    if (c == "insert") {
      dict.insert(s);
    } else if (c == "find") {
      if (dict.find(s) != dict.end()) {
        cout << "yes";
      } else {
        cout << "no";
      }
      cout << "\\n";
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
#include <unordered_set>

using namespace std;

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

  unordered_set<string> v;
  int n;
  cin >> n;
  for (int i; i < n; ++i) {
    string c, s;
    cin >> c >> s;
    if (c == "insert") {
      v.insert(s);
    } else if (c == "find") {
      if (find(v.begin(), v.end(), s) != v.end()) {
        cout << "yes";
      } else {
        cout << "no";
      }
      cout << "\\n";
    }
  }

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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <list>
#include <set>
#include <stack>
#include <vector>
using namespace std;

#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define PUSH(n, v)                                                             \\
  for (int i = 0; i < (n); i++) {                                              \\
    int j;                                                                     \\
    cin >> j;                                                                  \\
    v.push_back(j);                                                            \\
  }
#define ALL(v) v.begin(), v.end()

int getint(char c) {
  if (c == 'A')
    return 1;
  else if (c == 'C')
    return 2;
  else if (c == 'G')
    return 3;
  else
    return 4;
}

int getint(string s) {
  int j = 1;
  int a = 0;
  REP(i, s.size()) {
    a += j * getint(s[i]);
    j *= 5;
  }
  return a;
}

int main() {
  int n;
  cin >> n;
  set<int> st;
  REP(i, n) {
    string s, t;
    cin >> s >> t;
    int h = getint(t);
    if (s[0] == 'i')
      st.insert(h);
    else {
      if (st.find(h) != st.end())
        cout << "yes" << endl;
      else
        cout << "no" << endl;
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <list>
#include <set>
#include <stack>
#include <vector>
using namespace std;

#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define PUSH(n, v)                                                             \\
  for (int i = 0; i < (n); i++) {                                              \\
    int j;                                                                     \\
    cin >> j;                                                                  \\
    v.push_back(j);                                                            \\
  }
#define ALL(v) v.begin(), v.end()

int getint(char c) {
  if (c == 'A')
    return 1;
  else if (c == 'C')
    return 2;
  else if (c == 'G')
    return 3;
  else
    return 4;
}

int getint(string s) {
  int j = 1;
  int a = 0;
  REP(i, s.size()) {
    a += j * getint(s[i]);
    j *= 5;
  }
  return a;
}

int main() {
  int n;
  cin >> n;
  set<int> st;
  REP(i, n) {
    string s, t;
    cin >> s >> t;
    int h = getint(t);
    if (s == "insert")
      st.insert(h);
    else {
      if (st.find(h) != st.end())
        cout << "yes" << endl;
      else
        cout << "no" << endl;
    }
  }
  return 0;
}
Problem p02269 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <iostream>
#include <set>
#include <string>
using namespace std;
int main() {
  int n;
  cin >> n;
  string s, t;
  set<string> m;
  for (int i = 0; i < n; i++) {
    cin >> s >> t;
    if (s == "insert")
      m.insert(t);
    else if (s == "find") {
      if (m.find(t) == m.end())
        cout << "no" << endl;
      else
        cout << "yes" << endl;
    }
  }
  return 0;
}


Error: MLE

Fixed submission:

#include <iostream>
#include <set>
#include <string>
#include <vector>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<string> s(n), t(n);
  for (int i = 0; i < n; i++)
    cin >> s[i] >> t[i];
  set<string> m;
  for (int i = 0; i < n; i++) {
    if (s[i] == "insert")
      m.insert(t[i]);
    else if (s[i] == "find") {
      if (m.find(t[i]) == m.end())
        cout << "no" << endl;
      else
        cout << "yes" << endl;
    }
  }
  return 0;
}
Problem p02269 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define M 1000033 /* your task*/
#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 h(int key, int i) { return (h1(key) + i * h2(key)) % M; }

int find(char str[]) {
  long long key = getKey(str);
  for (int i = 0;; i++) {
    int idx = h(key, i);
    if (H[idx][0] == '\\0')
      return false;
    if (strcmp(str, H[idx]) == 0)
      return true;
  }
}

int insert(char str[]) {
  long long key = getKey(str);
  int idx = 0;
  for (int i = 0;; i++) {
    idx = h(key, i);
    if (H[idx][0] == '\\0')
      break;
  }
  strcpy(H[idx], str);
}

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: MLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define M 10000019 /* your task*/
#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 h(int key, int i) { return (h1(key) + i * h2(key)) % M; }

int find(char str[]) {
  long long key = getKey(str);
  for (int i = 0;; i++) {
    int idx = h(key, i);
    if (H[idx][0] == '\\0')
      return false;
    if (strcmp(str, H[idx]) == 0)
      return true;
  }
}

int insert(char str[]) {
  long long key = getKey(str);
  int idx = 0;
  for (int i = 0;; i++) {
    idx = h(key, i);
    if (H[idx][0] == '\\0')
      break;
  }
  strcpy(H[idx], str);
}

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;
}
Problem p02269 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

long long getKey(char str[]) {
  long long sum = 0, p = 1, i;
  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)); }

int find(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)
      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 (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");
      }
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>
#include <string.h>
#define M 10465
#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;
}

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) {
    } 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");
      }
    }
  }
}
Problem p02269 (C++) — buggy submission, verdict: Time Limit Exceeded

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

typedef long long ll;

int main() {
  ios::sync_with_stdio(false);
  set<string> st;
  int n;
  cin >> n;
  string com, str;
  for (int i = 0; i < n; i++) {
    cin >> com >> str;
    if (com == "insert") {
      st.insert(str);
    } else {
      auto itr = st.find(str);
      if (itr != st.end())
        cout << "yes\\n";
      else
        cout << "no\\n";
    }
  }
}


Error: TLE

Fixed submission:

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

typedef long long ll;

int main() {
  ios::sync_with_stdio(false);
  vector<string> vc;
  int n;
  cin >> n;
  string com, str;
  for (int i = 0; i < n; i++) {
    cin >> com >> str;
    if (com == "insert") {
      vc.push_back(str);
    } else {
      sort(vc.begin(), vc.end());
      if (binary_search(vc.begin(), vc.end(), str))
        cout << "yes\\n";
      else
        cout << "no\\n";
    }
  }
}
Problem p02269 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define MAX 244140625

int Hash[MAX];
char s[13];

int getChar(char);
int getKey();
int find();
void insert();

int main() {
  int n;
  char com[7];

  scanf("%d", &n);
  while (n--) {
    scanf("%s %s", com, s);

    if (com[0] == 'i') {
      insert();
    } else {
      if (find()) {
        puts("yes");
      } else {
        puts("no");
      }
    }
  }

  return 0;
}

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

int getKey() {
  int sum = 0, p = 1, i;

  for (i = 0; i < strlen(s); i++) {
    sum += p * (getChar(s[i]));
    p *= 5;
  }
  return sum;
}

int find() { return Hash[getKey()]; }

void insert() { Hash[getKey()] = 1; }

Error: TLE

Fixed submission:

#include <iostream>
#include <set>

using namespace std;

int n;
set<string> ss;
string s, str;

int main() {
  cin >> n;
  while (n--) {
    cin >> str;

    if (str[0] == 'i') {
      cin >> s;
      ss.insert(s);
    } else {
      cin >> s;
      if (ss.find(s) == ss.end()) {
        cout << "no" << endl;
      } else {
        cout << "yes" << endl;
      }
    }
  }

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

#include <iostream>
#include <set>

using namespace std;

int n;
set<string> ss;
string s, str;

int main() {
  ios::sync_with_stdio(false);

  cin >> n;
  while (n--) {
    cin >> str;

    if (str[0] == 'i') {
      cin >> s;
      ss.insert(s);
    } else {
      cin >> s;
      if (ss.find(s) == ss.end()) {
        cout << "no" << endl;
      } else {
        cout << "yes" << endl;
      }
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int n;
  set<string> s;
  string o, c;

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> o >> c;
    if (o == "insert") {
      s.insert(c);
    } else {
      if (s.count(c))
        cout << "yes" << endl;
      else
        cout << "no" << endl;
    }
  }
  return 0;
}
Problem p02269 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int main() {
  int n;
  scanf("%d", &n);

  map<string, bool> map;
  while (n--) {
    char s[8], d[16];
    scanf("%s %s", s, d);
    string ds(d);

    if (s[0] == 'i') {
      map[ds] = true;
    } else if (map[ds]) {
      printf("yes\\n");
    } else {
      printf("no\\n");
    }
  }

  return 0;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int calcIndex(char *str) {
  int index = 0, i = 0;
  bool flag = true;
  for (; str[i] != '\\0'; i++) {
    index += (str[i] == 'A'   ? 0
              : str[i] == 'C' ? 1
              : str[i] == 'T' ? 2
                              : 3) *
             pow(4, i);
    if (str[i] != 'A')
      flag = false;
  }
  if (flag) {
    index = 16777216 + i;
  }
  return index;
}

int main() {
  int n;
  scanf("%d", &n);

  int max = 1 + calcIndex("AAAAAAAAAAAA");
  bool map[max];
  for (int i = 0; i < max; i++) {
    map[i] = false;
  }

  while (n--) {
    char s[8], d[16];
    scanf("%s %s", s, d);

    if (s[0] == 'i') {
      map[calcIndex(d)] = true;
    } else if (map[calcIndex(d)]) {
      printf("yes\\n");
    } else {
      printf("no\\n");
    }
  }

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

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <sstream>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;

#define M 1527791 /* your task*/
#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;
  else
    return 0;
}

/* convert a string into an integer value */
long long getKey(char str[]) {
  long long sum = 0, p = 1;
  int j, i;
  j = strlen(str);
  for (i = 0; i < j; 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 h(int key, int i) { return (h1(key) + i * h2(key)) % M; }
bool find(char str[]) {
  int i = 0;
  long long j, key;
  key = getKey(str);
  while (1) {
    j = h(key, i);
    if (strcmp(H[j], str) == 0)
      return 1;
    else if (H[j][0] == '\\0' || i >= M)
      return 0;
    else
      i++;
  }
}

void insert(char str[]) {
  int i = 0;
  long long j, key;
  key = getKey(str);
  while (1) {
    j = h(key, i);
    if (strcmp(H[j], str) == 0)
      break;
    else if (H[j][0] == '\\0') {
      strcpy(H[j], str);
      break;
    } else
      i++;
  }
}

int main() {
  int i, n;
  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 <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <sstream>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;
char n[4][250000][12] = {};
int myatoi(char c) {
  if (c == 'A')
    return 0;
  else if (c == 'C')
    return 1;
  else if (c == 'G')
    return 2;
  else if (c == 'T')
    return 3;
}
void myfind(char *value, int y, int x) {
  bool flag = 0;
  for (int i = 0; i < y; i++) {
    if (strcmp(value, n[x][i]) == 0) {
      flag = 1;
      break;
    }
  }
  if (flag)
    cout << "yes" << endl;
  else
    cout << "no" << endl;
}
int a, c, g, t;
int main() {
  char s[2][13];
  int q;
  cin >> q;
  for (int j = 0; j < q; j++) {
    scanf("%s%s", s[0], s[1]);
    if (strcmp(s[0], "insert") == 0) {
      if (s[1][0] == 'A') {
        strcpy(n[0][a++], s[1]);
      }

      else if (s[1][0] == 'C')
        strcpy(n[1][c++], s[1]);
      else if (s[1][0] == 'G')
        strcpy(n[2][g++], s[1]);
      else
        strcpy(n[3][t++], s[1]);
    } else {
      if (s[1][0] == 'A')
        myfind(s[1], a, 0);
      else if (s[1][0] == 'C')
        myfind(s[1], c, 1);
      else if (s[1][0] == 'G')
        myfind(s[1], g, 2);
      else
        myfind(s[1], t, 3);
    }
  }

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

#include <bits/stdc++.h>
using namespace std;
const int C = 1046527;

char baca[C][13];

int hs(int key, int i) { return (key % C + i * (1 + key % (C - 1))) % C; }

int cToI(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;
}
int getKey(string tmp) {
  int sum = 0, p = 1, l = tmp.length();
  for (int i = 0; i < l; i++) {
    sum += p * cToI(tmp[i]);
    p *= 5;
  }
  return sum;
}

void ins(string str) {
  int key = getKey(str);
  for (int i = 0; i < C; i++) {
    int h = hs(key, i);
    if (strlen(baca[h]) == 0) {
      strcpy(baca[h], str.c_str());
      break;
    }
  }
}

int find(string str) {
  int key = getKey(str);
  for (int i = 0;; i++) {
    int h = hs(key, i);
    if (strlen(baca[h]) == 0) {
      return 0;
    } else if (strcmp(baca[h], str.c_str()) == 0) {
      return 1;
    }
  }
}

int main() {
  ios::sync_with_stdio(false);

  int cnt;
  cin >> cnt;
  string tmp;
  string key;
  for (int i = 0; i < cnt; i++) {
    cin >> tmp >> key;

    if (tmp[0] == 'i') {
      ins(key);
    } else {
      find(key) == 1 ? cout << "yes" << endl : cout << "no" << endl;
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const int C = 1046527;

char baca[C][13];

int hs(int key, int i) { return (key % C + i * (1 + key % (C - 1))) % C; }

int cToI(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;
}
int getKey(string tmp) {
  int sum = 0, p = 1, l = tmp.length();
  for (int i = 0; i < l; i++) {
    sum += p * cToI(tmp[i]);
  }
  return sum;
}

void ins(string str) {
  int key = getKey(str);
  for (int i = 0; i < C; i++) {
    int h = hs(key, i);
    if (strlen(baca[h]) == 0) {
      strcpy(baca[h], str.c_str());
      break;
    }
  }
}

int find(string str) {
  int key = getKey(str);
  for (int i = 0;; i++) {
    int h = hs(key, i);
    if (strlen(baca[h]) == 0) {
      return 0;
    } else if (strcmp(baca[h], str.c_str()) == 0) {
      return 1;
    }
  }
}

int main() {
  ios::sync_with_stdio(false);

  int cnt;
  cin >> cnt;
  string tmp;
  string key;
  for (int i = 0; i < cnt; i++) {
    cin >> tmp >> key;

    if (tmp[0] == 'i') {
      ins(key);
    } else {
      find(key) == 1 ? cout << "yes" << endl : cout << "no" << endl;
    }
  }

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

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

class Dictionary {
private:
  set<string> word;

public:
  void insert(string str) { word.insert(str); };
  void find(string str) {
    auto itr = word.find(str);
    cout << ((itr != word.end()) ? "yes" : "no") << endl;
  };
};

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  Dictionary dic;
  while (n--) {
    string order, str;
    cin >> order >> str;
    if (order == "insert") {
      dic.insert(str);
    } else if (order == "find") {
      dic.find(str);
    }
  }

  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  int n, pnt = 0;
  string order, str, dic[1000010];
  cin >> n;
  while (n--) {
    cin >> order >> str;
    if (order == "insert") {
      dic[pnt] = str;
      ++pnt;
    }
    if (order == "find") {
      bool exist = false;
      for (int i = 0; i < pnt; ++i) {
        if (dic[i] == str) {
          exist = true;
          break;
        }
      }
      if (exist)
        cout << "yes" << endl;
      else
        cout << "no" << endl;
    }
  }

  return 0;
}