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

// ALDS1_4_C Dictionary

#include <iostream>
#include <string>
#include <vector>
#define N_MAX 1046527 // 理屈はわからないが…

long dic[N_MAX] = {0};

int char2value(char c) {
  switch (c) {
  case 'A':
    return 1;
  case 'C':
    return 2;
  case 'G':
    return 3;
  case 'T':
    return 4;
  default:
    return 0;
  }
}

long data2value(std::string data) {
  long total = 0;

  for (int i = 0; i < data.size(); i++) {
    total = 5 * total + data[i];
  }

  return total;
}

long getHash1(long key) { return key % N_MAX; }

long getHash2(long key) { return (key % (N_MAX - 1)) + 1; }

void insertData(long data) {
  for (int i = 0;; i++) {
    long hash = (getHash1(data) + i * getHash2(data)) % N_MAX;
    // No data
    if (dic[hash] == 0) {
      dic[hash] = data;
      return;
    }
    // Same data
    else if (dic[hash] == data) {
      return;
    }
  }
}

bool findData(long data) {
  for (int i = 0;; i++) {
    long hash = (getHash1(data) + i * getHash2(data)) % N_MAX;
    // No data
    if (dic[hash] == 0) {
      return false;
    }
    // Match data
    else if (dic[hash] == data) {
      return true;
    }
  }
}

int main(int argc, char *argv[]) {
  std::string command;
  std::string data;
  std::vector<bool> result;
  int n;

  std::cin >> n;

  for (int i = 0; i < n; i++) {
    std::cin >> command >> data;
    long key = data2value(data);
    if (command == "insert") {
      insertData(key);
    } else if (command == "find") {
      result.push_back(findData(key));
    }
  }

  for (auto itr = result.begin(); itr != result.end(); itr++) {
    if (*itr) {
      std::cout << "yes" << std::endl;
    } else {
      std::cout << "no" << std::endl;
    }
  }

  return 0;
}


Error: TLE

Fixed submission:

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

int main(int argc, char const *argv[]) {
  int n;
  list<string> strList;
  list<bool> result;
  string command;
  string inputStr;

  ios::sync_with_stdio(false); // ????????????

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> command >> inputStr;
    // insert????????????
    if (command[0] == 'i') {
      strList.push_back(inputStr);
    }
    // find????????????
    else if (command[0] == 'f') {
      list<string>::iterator itr = strList.begin();
      for (; itr != strList.end(); itr++) {
        if (*itr == inputStr) {
          result.push_back(true);
          break;
        }
      }
      if (itr == strList.end())
        result.push_back(false);
    }
  }

  list<bool>::iterator itr = result.begin();
  for (; itr != result.end(); itr++) {
    if (*itr)
      cout << "yes\\n";
    else
      cout << "no\\n";
  }

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

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

int main() {
  int n;
  string a;
  string command;
  map<string, int> m;
  cin >> n;
  while (n--) {
    cin >> command;
    if (command == "insert") {
      cin >> a;
      m.insert(map<string, int>::value_type(a, 0));
    } else if (command == "find") {
      cin >> a;
      map<string, int>::iterator ma = m.find(a);
      if (ma != m.end()) {
        cout << "yes" << endl;
      } else {
        cout << "no" << endl;
      }
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  bool flag;
  int n;
  string a;
  string command;
  list<string> lst;
  cin >> n;
  while (n--) {
    cin >> command;
    if (command == "insert") {
      cin >> a;
      lst.push_front(a);
    } else if (command == "find") {
      cin >> a;
      flag = false;
      for (list<string>::iterator lit = lst.begin(); lit != lst.end(); lit++) {
        if (*lit == a) {
          flag = true;
        }
      }
      if (flag) {
        cout << "yes" << endl;
      } else {
        cout << "no" << endl;
      }
    }
  }
  return 0;
}
Problem p02269 (C++) — buggy submission, verdict: Time Limit Exceeded

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

string PopFront(string X) {
  string Y;
  for (int i = 1; i < X.size(); i++) {
    Y.push_back(X[i]);
  }
  return Y;
}

bool operator<(string &A, string &B) {
  int a = 0;
  int b = 0;
  while (!A.empty() && !B.empty()) {
    if ('A[0]' < 'B[0]') {
      a = 1;
      break;
    } else if ('A[0]' > 'B[0]') {
      b = 1;
      break;
    }
    A = PopFront(A);
    B = PopFront(B);
  }
  if (!A.empty()) {
    a = 1;
  } else if (!B.empty()) {
    b = 1;
  }
  return a < b;
}

void Judge(set<string> &RWord, string &Command, string &Word) {
  if (Command == "insert") {
    RWord.insert(Word);
  } else {
    set<string>::iterator it = RWord.find(Word);
    if (it != RWord.end()) {
      cout << "yes" << endl;
    } else {
      cout << "no" << endl;
    }
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  set<string> RWord;
  for (int i = 0; i < n; i++) {
    string Command;
    string Word;
    cin >> Command;
    cin >> Word;
    Judge(RWord, Command, Word);
  }
  return 0;
}

Error: TLE

Fixed submission:

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

string PopFront(string X) {
  string Y;
  for (int i = 1; i < X.size(); i++) {
    Y.push_back(X[i]);
  }
  return Y;
}

bool operator<(string &A, string &B) {
  int a = 0;
  int b = 0;
  while (!A.empty() && !B.empty()) {
    if ('A[0]' < 'B[0]') {
      a = 1;
      break;
    } else if ('A[0]' > 'B[0]') {
      b = 1;
      break;
    }
    A = PopFront(A);
    B = PopFront(B);
  }
  if (!A.empty()) {
    a = 1;
  } else if (!B.empty()) {
    b = 1;
  }
  return a < b;
}

void Judge(set<string> &RWord, string &Command, string &Word) {
  if (Command == "insert") {
    RWord.insert(Word);
  } else {
    if (binary_search(RWord.begin(), RWord.end(), Word)) {
      cout << "yes" << endl;
    } else {
      cout << "no" << endl;
    }
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  set<string> RWord;
  for (int i = 0; i < n; i++) {
    string Command;
    string Word;
    cin >> Command;
    cin >> Word;
    Judge(RWord, Command, Word);
  }
  return 0;
}
Problem p02269 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <string>

using namespace std;

struct List {
  string str;
  List *next;

  List() {
    str = "";
    next = NULL;
  }
};

struct Dict {
  List list[20000];

  int hash(string str) {
    int hash_num = 0;
    for (int i = 0; i < str.length(); i++) {
      int c = (int)str[i];
      hash_num += c * c * c + i * c * c + c * i * i + c;
    }
    return hash_num;
  }
  void insert(string str) {
    int key = hash(str) % 20000;
    List *target;
    List *item = new List();
    item->str = str;

    target = &list[key];
    while (target->next != NULL) {
      if (target->next->str == str)
        return;
      target = target->next;
    }
    target->next = item;
  }
  void find(string str) {
    int key = hash(str) % 20000;
    List *target;
    target = &list[key];
    if (target->next == NULL) {
      cout << "no" << endl;
      return;
    }
    target = target->next;
    while (true) {
      if (target->str == str) {
        cout << "yes" << endl;
        return;
      } else if (target->next == NULL) {
        cout << "no" << endl;
        return;
      } else {
        target = target->next;
      }
    }
  }
};

int main() {
  int n;
  cin >> n;
  string ope, str;
  Dict dict;
  for (int i = 0; i < n; i++) {
    cin >> ope >> str;
    if (ope == "insert") {
      dict.insert(str);
    } else if (ope == "find") {
      dict.find(str);
    }
  }
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>

using namespace std;

struct List {
  string str;
  List *next;

  List() {
    str = "";
    next = NULL;
  }
};

struct Dict {
  List list[10000];

  int hash(string str) {
    int hash_num = 0;
    for (int i = 0; i < str.length(); i++) {
      int c = (int)str[i];
      hash_num += c * c * c + i * c * c + c * i * i + c;
    }
    return hash_num;
  }
  void insert(string str) {
    int key = hash(str) % 10000;
    List *target;
    List *item = new List();
    item->str = str;

    target = &list[key];
    while (target->next != NULL) {
      if (target->next->str == str)
        return;
      target = target->next;
    }
    target->next = item;
  }
  void find(string str) {
    int key = hash(str) % 10000;
    List *target;
    target = &list[key];
    if (target->next == NULL) {
      cout << "no" << endl;
      return;
    }
    target = target->next;
    while (true) {
      if (target->str == str) {
        cout << "yes" << endl;
        return;
      } else if (target->next == NULL) {
        cout << "no" << endl;
        return;
      } else {
        target = target->next;
      }
    }
  }
};

int main() {
  int n;
  cin >> n;
  string ope, str;
  Dict dict;
  for (int i = 0; i < n; i++) {
    cin >> ope >> str;
    if (ope == "insert") {
      dict.insert(str);
    } else if (ope == "find") {
      dict.find(str);
    }
  }
}
Problem p02269 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <iostream>
#include <set>
#include <string>
using namespace std;
#define rep(x, to) for (int x = 0; x < (to); (x)++)

int main() {
  int n;
  char s[5];
  string t;
  set<string> Set;
  cin >> n;
  rep(i, n) {
    scanf("%s", s);
    if (s[0] == 'i') {
      cin >> t;
      Set.insert(t);
    } else {
      cin >> t;
      if (Set.find(t) == Set.end())
        printf("no\\n");
      else
        printf("yes\\n");
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <cstring>
#include <iostream>
#include <set>
#include <string>
using namespace std;
#define rep(x, to) for (int x = 0; x < (to); (x)++)

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

#include <algorithm>
#include <iostream>
#include <set>
#include <string>
int main(void) {
  std::ios_base::sync_with_stdio(false);
  int n;
  std::cin >> n;
  std::set<std::string> DICTIONARY;
  std::string COMMAND;
  std::string WORD;
  for (int i = 0; i < n; ++i) {
    std::cin >> COMMAND >> WORD;
    if (COMMAND == "insert") {

      DICTIONARY.insert(WORD);
    } else if (COMMAND == "find") {
      // if (std::find(DICTIONARY.begin(), DICTIONARY.end(), WORD) !=
      // DICTIONARY.end())
      if (DICTIONARY.find(WORD) != DICTIONARY.end()) {
        std::cout << "yes" << std::endl;
      } else {
        std::cout << "no" << std::endl;
      }
    }
  }
  //	system("pause");
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <set>
#include <string>
int main(void) {
  std::ios_base::sync_with_stdio(false);
  int n;
  std::cin >> n;
  std::set<std::string> DICTIONARY;
  std::string COMMAND;
  std::string WORD;
  for (int i = 0; i < n; ++i) {
    std::cin >> COMMAND >> WORD;
    if (COMMAND == "insert") {

      DICTIONARY.insert(WORD);
    } else if (COMMAND == "find") {

      if (std::find(DICTIONARY.begin(), DICTIONARY.end(), WORD) !=
          DICTIONARY.end()) {
        std::cout << "yes" << std::endl;
      } else {
        std::cout << "no" << std::endl;
      }
    }
  }
  //	system("pause");
  return 0;
}
Problem p02269 (C++) — buggy submission, verdict: Time Limit Exceeded

#pragma GCC optimize("O3")
#pragma GCC target("avx")
#include <stdio.h>
#include <string.h>
int n;
char com[15];
char str[15];

int C[1777771];

int g(char ch) {
  if (ch == 'A')
    return 1;
  if (ch == 'G')
    return 2;
  if (ch == 'T')
    return 3;
  return 4;
}

int f() {
  int res = 0;
  for (int i = 0; str[i] != '\\0'; i++) {
    res = res * 4 + g(str[i]);
  }
  return res;
}

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%s %s", com, str);

    int key = f();

    if (com[0] == 'f') {
      int ans = C[key % 1777771];
      if (ans)
        printf("yes\\n");
      else
        printf("no\\n");
    } else {
      C[key % 1777771] = 1;
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#pragma GCC optimize("O3")
#pragma GCC target("avx")
#include <stdio.h>
#include <string.h>
int n;
char com[15];
char str[15];
int A[1000000];
char B[1000000];
int C[1000000];

int g(char ch) {
  if (ch == 'A')
    return 1;
  if (ch == 'G')
    return 2;
  if (ch == 'T')
    return 3;
  return 4;
}

int f() {
  int res = 0;
  for (int i = 0; str[i] != '\\0'; i++) {
    res = res * 4 + g(str[i]);
  }
  return res;
}

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%s %s", com, str);

    int key = f();

    A[i] = key;
    B[i] = com[0];
    C[i] = 1;

    if (com[0] == 'f') {
      int ans = 0;
      for (int j = i - 1; j >= 0; j--) {
        if (A[j] == key) {
          ans = C[j];
          break;
        }
      }

      C[i] = ans;
      if (ans)
        printf("yes\\n");
      else
        printf("no\\n");
    }
  }
  return 0;
}
Problem p02269 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <string>

using namespace std;

#define M 16777216 // 4^12
#define L 14

int H[M][L] = {0};

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

/* convert a string into an integer value */
long long getKey(string str) {
  long long sum = 0, p = 1, i;
  for (i = 0; i < str.size(); i++) {
    sum += p * (getChar(str[i]));
    p *= 4;
  }
  return sum;
}

int find(string str) { return H[getKey(str)][str.size()]; }

int insert(string str) { return ++H[getKey(str)][str.size()]; }

int main() {
  int i, n;
  string str, cmd;
  cin >> n;
  for (i = 0; i < n; i++) {
    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 <iostream>
#include <string>
#include <vector>

using namespace std;

class Dictionary {
private:
  vector<string> d;
  int charToVal(char c) {
    if (c == 'A')
      return 1;
    else if (c == 'C')
      return 2;
    else if (c == 'G')
      return 3;
    else if (c == 'T')
      return 4;
    else
      return 0;
  }
  int strToKey(string s) {
    int key = 0;
    int p = 1;
    for (int i = 0; i < s.size(); i++) {
      key += p * charToVal(s[i]);
      p *= 5;
    }
    return key;
  }
  int binarySearch(string s, vector<string> &d) {
    int min, max, mid = 0;
    int key_s = strToKey(s);
    min = 0;
    max = d.size();
    while (min < max) {
      mid = (max + min) / 2;
      if (d[mid] == s) {
        return mid;
      } else if (key_s < strToKey(d[mid])) {
        max = mid;
      } else {
        min = mid + 1;
      }
    }
    return mid;
  }

public:
  Dictionary() { vector<string> *d = new vector<string>; }
  void insert(string s) {
    if (d.size() == 0) {
      d.insert(d.begin(), s);
    } else {
      int mid = binarySearch(s, d);
      if (strToKey(d[mid]) >= strToKey(s)) {
        d.insert(d.begin() + mid, s);
      } else {
        d.insert(d.begin() + mid + 1, s);
      }
    }
  }
  void find(string s) {
    if (d.size() == 0) {
      cout << "no" << endl;
    } else {
      int mid = binarySearch(s, d);
      if (s == d[mid]) {
        cout << "yes" << endl;
      } else {
        cout << "no" << endl;
      }
    }
  }
};

int main() {
  int n;
  cin >> n;
  Dictionary d;
  string cmd;
  string s;
  for (int i = 0; i < n; i++) {
    cin >> cmd;
    if (cmd == "insert") {
      cin >> s;
      d.insert(s);
    } else if (cmd == "find") {
      cin >> s;
      d.find(s);
    } else {
      break;
    }
  }
}
Problem p02269 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <map>
#include <string>

using namespace std;

int main() {
  map<string, int> dic;
  int n;
  string op, word;
  cin >> n;
  while (n-- > 0) {
    cin >> op >> word;
    switch (op[0]) {
    case 'i':
      dic[word] = 1;
      break;
    case 'f':
      if (dic[word]) {
        cout << "yes" << endl;
      } else {
        cout << "no" << endl;
      }
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

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

using namespace std;

bool Bsearch(string key, string A[], int len) {
  int l = 0, r = len - 1;
  while (l <= r) {
    int mid = l + (r - l) / 2;
    if (A[mid] > key)
      r = mid - 1;
    else if (A[mid] < key)
      l = mid + 1;
    else
      return true;
  }
  return false;
}

int main() {
  int n, flag = 0;
  string operation, str;
  vector<string> dic;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> operation >> str;
    if (operation == "insert") {
      dic.push_back(str);
      flag = 1;
    } else if (operation == "find") {
      if (flag == 1) {
        sort(dic.begin(), dic.end());
        flag = 0;
      }
      //			if (Bsearch(str, dic.data(), dic.size()) ==
      //true)
      if (binary_search(dic.begin(), dic.end(), str) == true)
        cout << "yes" << endl;
      else
        cout << "no" << endl;
    }
  }
  return 0;
}
Problem p02269 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

  int n;
  string cmd, dna;
  set<long long int> dictionary;

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> cmd >> dna;
    long long int x = 0;
    if (cmd == "insert") {
      for (int j = 0; j < dna.length(); j++) {
        if (dna[j] == 'A')
          x += 1 * pow((double)10, (double)(j + 1));
        else if (dna[j] == 'C')
          x += 2 * pow((double)10, (double)(j + 1));
        else if (dna[j] == 'G')
          x += 3 * pow((double)10, (double)(j + 1));
        else if (dna[j] == 'T')
          x += 4 * pow((double)10, (double)(j + 1));
      }
      dictionary.insert(x);
    } else if (cmd == "find") {
      for (int j = 0; j < dna.length(); j++) {
        if (dna[j] == 'A')
          x += 1 * pow((double)10, (double)(j + 1));
        else if (dna[j] == 'C')
          x += 2 * pow((double)10, (double)(j + 1));
        else if (dna[j] == 'G')
          x += 3 * pow((double)10, (double)(j + 1));
        else if (dna[j] == 'T')
          x += 4 * pow((double)10, (double)(j + 1));
      }

      if (dictionary.find(x) == dictionary.end())
        cout << "no" << endl;
      else
        cout << "yes" << endl;
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

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

void insert(vector<string> *A, string str) { (*A).push_back(str); }

void find(vector<string> A, string str) {
  vector<string>::iterator iter = find(A.begin(), A.end(), str);
  if (iter != A.end())
    cout << "yes" << endl;
  else
    cout << "no" << endl;
}

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

  int n;
  string cmd, dna;
  vector<string> dictionary;

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> cmd >> dna;
    if (cmd == "insert")
      insert(&dictionary, dna);
    else if (cmd == "find")
      find(dictionary, dna);
  }

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

#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef pair<int, int> P;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repi(i, a, b) for (int i = int(a); i < (b); i++)
#define all(x) x.begin(), x.end()

const ll mod = 1e9 + 7;
const ll INF = 1e9;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
  set<string> s;
  int n;
  cin >> n;
  rep(i, n) {
    string q;
    string x;
    cin >> q >> x;
    if (q == "insert") {
      s.insert(x);
    } else {
      cout << (s.count(x) ? "yes" : "no") << endl;
    }
  }
  return 0;
}


Error: WA

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <string>

using namespace std;

struct node {
  node *next;
  node *prev;
  string dic;
};

node *head;

void initialize() {
  head = (node *)malloc(sizeof(node));
  head->next = head;
  head->prev = head;
}

void insert(string gene) {
  node *p = (node *)malloc(sizeof(node));

  p->dic = gene;
  p->next = head->next;
  head->next->prev = p;
  p->prev = head;
  head->next = p;
}

bool search(string key) {
  node *cur = (node *)malloc(sizeof(node));
  cur = head->next;

  while (cur != head) {
    if (cur->dic == key) {
      return true;
    }
    cur = cur->next;
  }

  return false;
}

int main() {
  int n;
  string str, gene;

  initialize();

  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> str >> gene;

    if (str == "insert") {
      insert(gene);
    } else {
      if (search(gene)) {
        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(void) {
  int n;
  string text, key;

  cin >> n;
  getline(cin, text);
  map<string, char> S;

  for (int i = 0; i < n; i++) {
    getline(cin, text);
    switch (text[0]) {
    case 'i':
      S[text.substr(7)] = 1;
      break;
    case 'f':
      if (S.find(text.substr(5)) == S.end())
        cout << "no" << endl;
      else
        cout << "yes" << endl;
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

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

int main(void) {
  int n;
  string text, key;

  cin >> n;
  getline(cin, text);
  vector<string> S(n, "            ");

  for (int i = 0; i < n; i++) {
    getline(cin, text);
    switch (text[0]) {
    case 'i':
      S[i] = text.substr(7);
      break;
    case 'f':
      S[i] = "";
      bool f = false;
      for (int j = 0; j < i; j++)
        if (S[j] == text.substr(5)) {
          f = true;
          break;
        }
      if (f)
        cout << "yes" << endl;
      else
        cout << "no" << endl;
    }
  }

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

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

int main() {
  int n;
  unordered_set<string> d;
  string ope, contents;

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> ope >> contents;
    if (ope == "insert")
      d.insert(contents);
    else if (ope == "find") {
      if (d.count(contents) >= 1)
        cout << "yes" << endl;
      else
        cout << "no" << endl;
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int n;
  set<string> d;
  string ope, contents;

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> ope >> contents;
    if (ope == "insert")
      d.insert(contents);
    else if (ope == "find") {
      if (d.count(contents) == 1)
        cout << "yes" << endl;
      else
        cout << "no" << endl;
    }
  }

  return 0;
}