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

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

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

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

  int n;
  cin >> n;

  set<string> S;

  string st1, st2;

  REP(i, n) {
    cin >> st1 >> st2;

    if (st1 == "insert") {
      S.insert(st2);
    }

    else { // find
      (S.find(st2) != S.end()) ? cout << "yes" : cout << "no";
      cout << endl;
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

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

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

  int n;
  cin >> n;

  vector<string> S;

  string st1, st2;

  REP(i, n) {
    cin >> st1 >> st2;

    if (st1 == "insert") {
      S.push_back(st2);
    }

    else { // find
      sort(S.begin(), S.end());
      (binary_search(S.begin(), S.end(), st2)) ? cout << "yes" : cout << "no";
      cout << endl;
    }
  }
  return 0;
}
Problem p02269 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <cassert>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
  auto encodeString = [](const string &str) {
    auto encodeChar = [](char c) {
      switch (c) {
      case 'A':
        return 1;
      case 'C':
        return 2;
      case 'G':
        return 3;
      case 'T':
        return 4;
      default:
        assert(false);
      }
    };
    auto pow = [](auto b, auto e) {
      int r{1};
      for (auto i = 0; i < e; ++i) {
        r *= b;
      }
      return r;
    };
    vector<char> v;
    transform(begin(str), end(str), back_inserter(v), encodeChar);
    int r{0};
    for (size_t i = 0; i < v.size(); ++i) {
      r += v[i] * pow(5, i);
    }
    return r;
  };
  vector<bool> b(244140624 + 1);

  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    string instruction;
    string s;
    cin >> instruction >> s;
    if (instruction == "insert") {
      b[encodeString(s)] = true;
    } else {
      if (b[encodeString(s)]) {
        cout << "yes" << endl;
      } else {
        cout << "no" << endl;
      }
    }
  }
}

Error: -11

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cassert>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
  auto encodeString = [](const string &str) {
    auto encodeChar = [](char c) {
      switch (c) {
      case 'A':
        return 1;
      case 'C':
        return 2;
      case 'G':
        return 3;
      case 'T':
        return 4;
      default:
        assert(false);
      }
    };
    auto pow = [](auto b, auto e) {
      int r{1};
      for (auto i = 0; i < e; ++i) {
        r *= b;
      }
      return r;
    };
    vector<char> v;
    transform(begin(str), end(str), back_inserter(v), encodeChar);
    int r{0};
    for (size_t i = 0; i < v.size(); ++i) {
      r += v[i] * pow(5, i);
    }
    return r;
  };

  bitset<244140624 + 1> b;

  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    string instruction;
    string s;
    cin >> instruction >> s;
    if (instruction == "insert") {
      b[encodeString(s)] = true;
    } else {
      if (b[encodeString(s)]) {
        cout << "yes" << endl;
      } else {
        cout << "no" << endl;
      }
    }
  }
}
Problem p02269 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define rep(i, a) REP(i, 0, a)
#define REP(i, a, b) for (int i = a; i < b; ++i)
#define rrep(i, a) RREP(i, a, 0)
#define RREP(i, a, b) for (int i = a; i >= b; --i)
#define repll(i, a) REPLL(i, 0, a)
#define REPLL(i, a, b) for (ll i = a; i < b; ++i)
#define rrepll(i, a) RREPLL(i, a, 0)
#define RREPLL(i, a, b) for (ll i = a; i >= b; --i)

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int, int> P;
typedef std::pair<int, P> PP;
const double PI = 3.14159265358979323846;
const double esp = 1e-9;
const int infi = (int)1e+9 + 10;
const ll infll = (ll)1e+18 + 10;

int n;
std::set<std::string> s;

int main() {
  std::cin >> n;

  rep(i, n) {
    char p[20], q[20];
    scanf("%s %s", &p, &q);
    if (p[0] == 'i')
      s.insert(q);
    else
      printf("%s\\n", (s.find(q) != s.end() ? "yes" : "no"));
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define rep(i, a) REP(i, 0, a)
#define REP(i, a, b) for (int i = a; i < b; ++i)
#define rrep(i, a) RREP(i, a, 0)
#define RREP(i, a, b) for (int i = a; i >= b; --i)
#define repll(i, a) REPLL(i, 0, a)
#define REPLL(i, a, b) for (ll i = a; i < b; ++i)
#define rrepll(i, a) RREPLL(i, a, 0)
#define RREPLL(i, a, b) for (ll i = a; i >= b; --i)

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int, int> P;
typedef std::pair<int, P> PP;
const double PI = 3.14159265358979323846;
const double esp = 1e-9;
const int infi = (int)1e+9 + 10;
const ll infll = (ll)1e+18 + 10;

int n;
std::set<std::string> s;

int main() {
  std::cin >> n;

  rep(i, n) {
    std::string p, q;
    std::cin >> p >> q;
    if (p == "insert")
      s.insert(q);
    else
      std::cout << (s.find(q) != s.end() ? "yes" : "no") << std::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;
  string order;
  string str;
  map<string, string> mp;

  cin >> n;
  do {
    cin >> order;
    cin >> str;
    if (order == "insert") {
      mp[str] = "yes\\n";
    } else if (order == "find") {
      auto it = mp.find(str);
      if (it != mp.end()) {
        cout << mp[str];
      } else {
        cout << "no\\n";
      }
    }
    n--;
  } while (n != 0);

  return 0;
}


Error: TLE

Fixed submission:

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

using namespace std;

int main() {
  map<string, string> mp;

  int n;
  cin >> n;

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

    if (order == "insert") {
      mp.insert(make_pair(str, "yes"));
    } else if (order == "find") {
      if (mp.count(str) == 0) {
        cout << "no\\n";
      } else {
        cout << mp.at(str) << endl;
      }
    }
  }

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

#include <iostream>
#include <set>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  set<string> dict;
  string cmd, key;
  for (int i = 0; i < n; i++) {
    cin >> cmd >> key;
    if ("insert" == cmd) {
      dict.insert(key);
    } else {
      if (dict.end() != dict.find(key)) {
        cout << "yes\\n";
      } else {
        cout << "no\\n";
      }
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <set>

using namespace std;

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

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

#include <algorithm>
#include <iostream>
#include <set>
#include <string>
using namespace std;
int main() {
  std::ios_base::sync_with_stdio(false);
  set<string> st;
  int n;
  cin >> n;
  while (n--) {
    string BUFF, c;
    cin >> BUFF >> c;
    if (BUFF == "insert")
      st.insert(c);
    else
      cout << (st.find(c) != st.end() ? "yes" : "no") << endl;
  }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define EACH(i, c)                                                             \\
  for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                                               \\
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"                       \\
       << " " << __FILE__ << endl;
#define ALL(a) (a).begin(), (a).end()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

using namespace std;

#define M 1046527

class Dictionary {
private:
  vector<string> data;
  map<int, string> m;

public:
  void insert(string str);
  void hash_Insert(string str);
  bool find(string str);
  bool hash_Find(string str);
  int get_Kay(string str);
  int hash_1(int kay);
  int hash_2(int kay);
};

int Dictionary::hash_1(int kay) { return kay % M; }
int Dictionary::hash_2(int kay) { return 1 + (kay % (M - 1)); }

int Dictionary::get_Kay(string str) {
  int k = 0;
  REP(i, (int)str.length()) { k += (int)str[i] * pow(10, i); }
  return k;
}

void Dictionary::insert(string str) {
  if (!Dictionary::find(str))
    data.PB(str);
}
void Dictionary::hash_Insert(string str) {
  int i = 0;
  int hashed_Kay;
  int kay = get_Kay(str);
  while (true) {
    hashed_Kay = hash_1(kay) + i * hash_2(kay);
    if (m[hashed_Kay] == "")
      break;
  }
  m[hashed_Kay] = str;
}

bool Dictionary::find(string str) {
  if (std::find(ALL(data), str) != data.end())
    return true;
  else
    return false;
}
bool Dictionary::hash_Find(string str) {
  int i = 0;
  int hashed_Kay;
  int kay = get_Kay(str);
  while (true) {
    hashed_Kay = hash_1(kay) + i * hash_2(kay);
    if (m[hashed_Kay] == str)
      return true;
    else if (m[hashed_Kay].length() == 0)
      return false;
  }
}

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

  int n;
  cin >> n;

  string op;
  string word;
  Dictionary dic;

  REP(_, n) {
    cin >> op;
    cin >> word;
    if (op[0] == 'i')
      dic.hash_Insert(word);
    else if (dic.hash_Find(word))
      cout << "yes"
           << "\\n";
    else
      cout << "no"
           << "\\n";
  }
}
Problem p02269 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <cstring>
#include <iostream>

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

char H[M][L];

//????¬???¬??¢?????°???
int getint(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 * (getint(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[10];
  memset(H, 0, sizeof(H));
  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 <cstdio>
#include <cstring>
#include <iostream>

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

char H[M][L];

//????¬???¬??¢?????°???
int chartoint(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 * (chartoint(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);
  i = 0;
  while (1) {
    h = (h1(key) + i * h2(key)) % M;
    if (strcmp(H[h], str) == 0)
      return 1;
    else if (strlen(H[h]))
      return 0;
    i++;
  }
  return 0;
}

int insert(char str[]) {
  long long key, i, h;
  key = getkey(str);
  i = 0;
  while (1) {
    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;
    }
    i++;
  }
  return 0;
}

int main() {
  int i, n, h;
  char str[L], com[10];
  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 <cstdio>
#include <cstring>
#include <iostream>
#include <set>
#include <string>

using namespace std;

int main() {
  int N;
  char dstr[13];
  string str;
  set<string> dset;
  cin >> N;
  for (int i = 0; i < N; i++) {
    scanf("%s", dstr);
    str = dstr;
    if (str == "insert") {
      cin >> str;
      dset.insert(str);
    } else {
      scanf("%s", dstr);
      str = dstr;
      if (dset.count(str)) {
        cout << "yes" << endl;
      } else {
        cout << "no" << endl;
      }
    }
  }
}

Error: TLE

Fixed submission:

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

using namespace std;

int main() {
  int N;
  string str;
  set<string> dset;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> str;
    if (str == "insert") {
      cin >> str;
      dset.insert(str);
    } else {
      cin >> str;
      if (dset.count(str)) {
        cout << "yes" << endl;
      } else {
        cout << "no" << endl;
      }
    }
  }
}
Problem p02269 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using namespace std;

static inline int charToInt(char c) {
  switch (c) {
  case 'A':
    return 0;
  case 'C':
    return 1;
  case 'G':
    return 2;
  case 'T':
    return 3;
  default:
    return -1;
  }
}

static inline int strToInt(const string &str) {
  int total = charToInt(str[0]);
  int cur;
  for (int i = 1; i < str.length(); i++) {
    cur = charToInt(str[i]);
    total += pow(4, i) + pow(4, i) * cur;
  }
  //  cout << " " << total;
  return total;
}

int main() {
  int n;
  cin >> n;

  vector<bool> dictionary(static_cast<size_t>(pow(4, 12)) + 4, false);
  string command, str;

  for (int i = 0; i < n; i++) {
    cin >> command >> str;
    if (command[0] == 'i') {
      dictionary[strToInt(str)] = true;
    } else {
      cout << (dictionary[strToInt(str)] ? "yes" : "no") << endl;
    }
  }
  return 0;
}


Error: TLE

Fixed submission:

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

using namespace std;

static vector<string> dicA, dicC, dicG, dicT;

static inline vector<string> &getDictionary(char first) {
  switch (first) {
  case 'A':
    return dicA;
  case 'C':
    return dicC;
  case 'G':
    return dicG;
  case 'T':
  default:
    return dicT;
  }
}

int main() {
  int n;
  cin >> n;

  string command, str;
  for (int i = 0; i < n; i++) {
    cin >> command >> str;
    auto &dic = getDictionary(str[0]);
    if (command[0] == 'i') {
      dic.push_back(str);
    } else {
      const bool found = (dic.end() != find(dic.begin(), dic.end(), str));
      cout << (found ? "yes" : "no") << endl;
    }
  }

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

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

const int L = 14;
const int M = 1046527;

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 = 0;
  key = getKey(str);
  while (1) {
    int h = (h1(key) + i * h2(key)) % M;
    if (strcmp(H[h], str) == 0)
      return 1;
    else if (strlen(H[h]) == 0)
      return 0;
    i++;
  }
  return 0;
}

void insert(char str[]) {

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

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

Fixed submission:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define INF 0x3f3f3f3f
#define NIL (-1)
// #define M 1000003
#define M 1046527
using namespace std;
int T[M + 1];
void trans(char *s) {
  for (int i = 0; i < strlen(s); i++) {
    if (s[i] == 'A')
      s[i] = '4';
    else if (s[i] == 'C')
      s[i] = '1';
    else if (s[i] == 'G')
      s[i] = '2';
    else if (s[i] == 'T')
      s[i] = '3';
  }
}
int stringToInt(char s[]) {
  int t = 0;
  int p = 1;
  for (int i = strlen(s) - 1; i >= 0; i--) {
    t += (s[i] - '0') * p;
    p *= 5;
  }
  return t;
}
int h1(int a) { return (int)(a % M); }
int h2(int a) { return 1 + (int)(a % (M - 1)); }
int h(int a, int i) { return (h1(a) + i * h2(a)); }

void insert(int c) {
  int i = 0;
  while (true) {
    int temp = h(c, i);
    if (T[temp] == NIL) {
      T[temp] = c;
      return;
    } else {
      i++;
    }
  }
}
int find(int d) {
  int i = 0;
  while (true) {
    int temp = h(d, i);
    if (T[temp] == NIL) {
      return -1;
    } else if (T[temp] == d) {
      return 1;
    } else {
      i++;
      if (i >= M)
        return -1;
    }
  }
}
int main() {
  for (int i = 0; i < M; i++)
    T[i] = NIL;

  int n;
  scanf("%d", &n);
  while (n--) {
    char a[10], b[14];
    scanf("%s %s", a, b);
    if (a[0] == 'i') {
      trans(b);
      int c = stringToInt(b);
      insert(c);
    } else {
      trans(b);
      int d = stringToInt(b);
      if (find(d) != -1) {
        printf("yes\\n");
      } else {
        printf("no\\n");
      }
    }
  }

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

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

long long n;

long long *T;

void insert(long long a) {
  for (long long i = 0; i < n; i++) {
    long long j = (((a % n) + i * (1 + a % (n - 1))) % n);
    if (T[j] == '\\0') {
      T[j] = a;
      break;
    }
  }
}

string findx(long long a) {
  for (long long i = 0; i < n; i++) {
    long long j = (((a % n) + i * (1 + a % (n - 1))) % n);
    if (T[j] == a) {
      return "yes";
    } else if (T[j] == '\\0') {
      return "no";
    }
  }
}

int main() {

  cin >> n;

  string s, x;

  long long cnt = 0;

  string *yn = new string[n];

  T = new long long[n];

  for (long long i = 0; i < n; i++) {

    cin >> s >> x;

    long long a = 0, b = 1;

    for (long long i = 0; i < (long long)x.size(); i++) {

      if (x[i] == 'A') {
        a = a + 1 * b;
      } else if (x[i] == 'C') {
        a = a + 2 * b;
      } else if (x[i] == 'G') {
        a = a + 3 * b;
      } else if (x[i] == 'T') {
        a = a + 4 * b;
      }

      b = b * 10;
    }

    if (s == "insert") {
      insert(a);
    } else if (s == "find") {
      yn[cnt] = findx(a);
      cnt++;
    }
  }

  for (long long i = 0; i < cnt; i++) {
    cout << yn[i] << endl;
  }
  return 0;
}


Error: 0

Fixed submission:

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

int n;

int T[1000000];

void insert(int a) {
  for (int i = 0; i < n; i++) {
    long long j = (((a % n) + i * (1 + a % (n - 1))) % n);
    if (T[j] == '\\0') {
      T[j] = a;
      break;
    }
  }
}

string findx(int a) {
  for (int i = 0; i < n; i++) {
    long long j = (((a % n) + i * (1 + a % (n - 1))) % n);
    if (T[j] == a) {
      return "yes";
    } else if (T[j] == '\\0') {
      return "no";
    }
  }
}

int main() {

  cin >> n;

  string s, x;

  int cnt = 0;

  string *yn = new string[n];

  for (int i = 0; i < n; i++) {

    cin >> s >> x;

    int a = 0, b = 1;

    for (int i = 0; i < (int)x.size(); i++) {

      if (x[i] == 'A') {
        a = a + 1 * b;
      } else if (x[i] == 'C') {
        a = a + 2 * b;
      } else if (x[i] == 'G') {
        a = a + 3 * b;
      } else if (x[i] == 'T') {
        a = a + 4 * b;
      }

      b = b * 10;
    }

    if (s == "insert") {
      insert(a);
    } else if (s == "find") {
      yn[cnt] = findx(a);
      cnt++;
    }
  }

  for (int i = 0; i < cnt; i++) {
    cout << yn[i] << endl;
  }
  return 0;
}
Problem p02269 (C++) — buggy submission, verdict: Time Limit Exceeded

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_4_C&lang=jp
#include <iostream>
#include <set>
#include <string>
#include <vector>
using namespace std;

int main() {
  std::set<string> dic;

  int count;
  cin >> count;

  for (int i = 0; i < count; i++) {
    string buf1, buf2;
    cin >> buf1 >> buf2;
    if (buf1 == "insert") {
      dic.insert(buf2);
    } else {
      if (dic.count(buf2) > 0)
        printf("yes\\n");
      else
        printf("no\\n");
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_4_C&lang=jp
#include <iostream>
#include <set>
#include <string>
#include <vector>
using namespace std;

int main() {
  std::set<string> dic;

  int count;
  cin >> count;

  string str1 = "insert", str2 = "find";

  for (int i = 0; i < count; i++) {
    string buf1, buf2;
    cin >> buf1 >> buf2;
    if (buf1 == str1) {
      dic.insert(buf2);
    } else {
      if (dic.count(buf2) > 0)
        cout << "yes" << endl;
      else
        cout << "no" << endl;
    }
  }
  return 0;
}