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

#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
typedef long long ll;

using namespace std;

int main() {
  ll n, tmp = 1, j;
  cin >> n;
  // string *s;
  string str;
  vector<string> s(n);
  // s = new string[n];
  /*
  cin >> s[0];
  for(ll i = 1; i < n; i++){
      cin >> s[tmp];
      for(j = 0; j < tmp; j++){
          //cout << s[j] << tmp << endl;
          if(s[j] == s[tmp]) break;
      }
      //cout << j << tmp << endl;
      if(j == tmp){
          tmp++;
      }
  }
  */
  /*
  for(ll i = 0; i < n; i++){
      cin >> s[i];
  }

  for(ll i = 0; i < n - 1; i++){
      for(ll j = i+1; j < n; j++){
          if(s[i] == s[j]) tmp++;
      }
  }
  */
  for (ll i = 0; i < n; i++) {
    cin >> s[i];
  }
  sort(s.begin(), s.end());
  for (ll i = 0; i < n - 1; i++) {
    if (s[i] != s[i + 1])
      tmp++;
  }
  cout << tmp << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
typedef long long ll;

using namespace std;

int main() {
  ll n, tmp = 1, j;
  cin >> n;
  string *s;
  string str;
  s = new string[n];

  cin >> s[0];
  for (ll i = 1; i < n; i++) {
    cin >> s[tmp];
    for (j = 0; j < tmp; j++) {
      // cout << s[j] << tmp << endl;
      if (s[j] == s[tmp])
        break;
    }
    // cout << j << tmp << endl;
    if (j == tmp) {
      tmp++;
    }
  }
  /*
  for(ll i = 0; i < n; i++){
      cin >> s[i];
  }

  for(ll i = 0; i < n - 1; i++){
      for(ll j = i+1; j < n; j++){
          if(s[i] == s[j]) tmp++;
      }
  }
  */
  cout << tmp << endl;
  return 0;
}
Problem p02701 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <cstdint>   // int64_t, int*_t
#include <cstdio>    // printf
#include <deque>     // deque
#include <iostream>  // cout, endl, cin
#include <map>       // map
#include <queue>     // queue, priority_queue
#include <set>       // set
#include <stack>     // stack
#include <string>    // string, to_string, stoi
#include <tuple>     // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
using namespace std;
int main() {
  int N;
  cin >> N;
  string S[N];
  for (int i = 0; i < N; i++)
    cin >> S[i];
  set<string> a;
  for (int i = 0; i < N; i++)
    a.insert(S[i]);
  cout << a.size();

  return 0;
}

Error: -8

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int A = (a + d - 1) / d;
  int T = (c + b - 1) / b;
  if (A >= T) {
    cout << "Yes" << endl;
  } else
    cout << "No" << endl;
  return 0;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define ll long long
#define MAX 10000000
#define SENTINEL 2e10

int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  int count = 0;
  set<string> se;
  rep(i, n) {
    string tmp;
    cin >> tmp;
    se.insert(tmp);
  }

  cout << se.size() << endl;
}

Error: TLE

Fixed submission:

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define ll long long
#define MAX 10000000
#define SENTINEL 2e10

int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  int count = 0;
  rep(i, n) {
    cin >> s[i];
    count++;
    for (int j = 0; j <= i; j++) {
      if (i == j)
        continue;
      if (s[i] == s[j]) {
        count--;
        break;
      }
    }
  }
  cout << count << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <math.h>
#include <set>
#include <string>
#include <vector>
using namespace std;

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

  vector<string> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  sort(a.begin(), a.end());
  a.erase(unique(a.begin(), a.end()), a.end());

  cout << a.size() << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <math.h>
#include <set>
#include <string>
#include <vector>
using namespace std;

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

  vector<string> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  vector<string> b(0);
  int ans = 0;
  int flg = 0;

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < b.size(); j++) {
      if (b[j] == a[i]) {
        flg = 1;
      }
    }

    if (flg == 0) {
      b.push_back(a[i]);
      ans++;
    }
    flg = 0;
  }

  cout << ans << endl;

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

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

int main() {
  int N;
  cin >> N;
  set<string> S;
  for (int i = 0; i < N; i++) {
    string a;
    cin >> a;
    S.insert(a);
  }
  cout << S.size() << endl;
}

Error: -11

Fixed submission:

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

struct node {
  string key;
  node *left, *right;
};
void pushtree(node *p, node *tree);

long int c = 1;

void show(node *tree) {
  if (tree == nullptr) {
    return;
  }
  show(tree->left);
  cout << tree->key;
  show(tree->right);
}

int main() {
  int N;
  cin >> N;
  int count = 1;
  string input;
  int ju = 1;
  node *tree;
  tree = new node;
  cin >> tree->key;
  // cin>>tree->key;
  vector<node *> p(200000);
  for (int i = 1; i < N; i++) {
    cin >> input;
    p.at(i) = new node;
    p.at(i)->key = input;
    pushtree(p.at(i), tree);

    /*for(int j=0;j<S.size()-1;j++){
        if(S.at(j)==input){
            S.pop_back();
            break;
        }
    }*/
  }
  cout << c << endl;
}

void pushtree(node *p, node *tree) {
  if (tree == nullptr) {
    *tree = *p;
    c++;
    return;
  }
  if (p->key == tree->key) {
    return;
  }
  if (p->key > tree->key) {
    pushtree(p, tree->right);
  }
  if (p->key < tree->key) {
    pushtree(p, tree->left);
  }
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  int count = 1;
  for (int i = 0; i < n; i++) {
    cin >> s.at(i);
  }
  sort(s.begin(), s.end());
  for (int i = 1; i < n; i++) {
    if (s.at(i) != s.at(i - 1)) {
      count++;
    }
  }
  cout << count << endl;
}


Error: TLE

Fixed submission:

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

int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  int count = 0;
  bool d = true;
  for (int i = 0; i < n; i++) {
    cin >> s.at(i);
    d = true;
    for (int j = 0; j < i; j++) {
      if (s.at(i) == s.at(j)) {
        d = false;
        break;
      }
    }
    if (d) {
      count++;
    }
  }
  cout << count << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(), x.end()

int main() {
  int n;
  int c = 0;
  cin >> n;
  vector<string> s(n);
  for (int i = 0; i < n; i++)
    cin >> s[i];
  sort(ALL(s));
  for (int i = 0; i < n - 1; i++) {
    if (s[i] == s[i + 1])
      c++;
  }
  cout << n - c;
  return 0;
}


Error: WA

Fixed submission:

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

int main() {
  int a;
  int s = 0;
  int d = 0;
  string mojiretu[20000];
  cin >> a;

  for (int i = 0; i < a; i++) {
    string str;
    cin >> str;
    mojiretu[i] = str;
  }

  for (int f = 0; f < a; f++) {
    string str2 = mojiretu[f];
    for (d; d < a; d++) {

      if (d != f) {
        string str3 = mojiretu[d];
        if (str2 == str3) {
          s++;
        }
      }
    }
    d = f + 1;
  }
  a = a - s / 2;
  cout << a << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#include <set>
using namespace std;
#define rep0(i, n) for (i = 0; i < n; i++)
#define rep1(i, n) for (i = 1; i < n; i++)
int main() {
  int num;
  int i;
  set<string> se;
  string str;

  cin >> num;

  rep0(i, num) {
    cin >> str;
    se.insert(str);
  }

  cout << se.size() << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep0(i, n) for (i = 0; i < n; i++)
#define rep1(i, n) for (i = 1; i < n; i++)
#define test(a) cout << "*" << a << endl;
int main() {
  int num;
  int i, j;
  int numOnly = 1;
  int numKaburi = 0;
  int breakFrag = 0;
  string s[200000];
  string sOnly[200000];

  cin >> num;
  rep0(i, num) cin >> s[i];

  sOnly[0] = s[0];

  rep1(i, num) {
    rep0(j, numOnly) {
      if (s[i] == sOnly[j]) {
        numKaburi++;
        breakFrag = 1;
        break;
      }
    }

    if (breakFrag == 0) {
      sOnly[numOnly] = s[i];
      numOnly++;
    }
    breakFrag = 0;
  }

  cout << num - numKaburi << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
typedef unsigned long long ull;
ull base = 131;
ull a[200010];
char s[11];
int n, ans = 1;
int prime = 233317;
ull mod = 212370440130137957ll;
ull hashe(char s[]) {
  int len = strlen(s);
  ull ans = 0;
  for (int i = 0; i < len; i++)
    ans = (ans * base + (ull)s[i]) % mod + prime;
  return ans;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%s", s);
    a[i] = hashe(s);
  }
  sort(a + 1, a + n + 1);
  for (int i = 1; i < n; i++) {
    if (a[i] != a[i + 1])
      ans++;
  }
  printf("%d", ans);
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
typedef unsigned long long ull;
ull base = 131;
ull a[10010];
char s[10010];
int n, ans = 1;
ull hashs(char s[]) {
  int len = strlen(s);
  ull ans = 0;
  for (int i = 0; i < len; i++)
    ans = ans * base + (ull)s[i];
  return ans & 0x7fffffff;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%s", s);
    a[i] = hashs(s);
  }
  sort(a + 1, a + n + 1);
  for (int i = 2; i <= n; i++)
    if (a[i] != a[i - 1])
      ans++;
  printf("%d\\n", ans);
}
Problem p02701 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

string s[300010];
map<string, int> mp;
int n;

int main() {
  cin >> n;
  //	for(register int i = 1; i <= n; i++) cin >> s[i];
  for (register int i = 1; i <= n; i++) {
    cin >> s[i];
    mp[s[i]]++;
  }
  int jsq = 0;
  map<string, int>::iterator iter;
  for (iter = mp.begin(); iter != mp.end(); iter++) {
    if (iter->second >= 1)
      jsq++;
  }
  cout << jsq;
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

string s[100010];
map<string, int> mp;
int n;

int main() {
  cin >> n;
  //	for(register int i = 1; i <= n; i++) cin >> s[i];
  for (register int i = 1; i <= n; i++) {
    cin >> s[i];
    mp[s[i]]++;
  }
  int jsq = 0;
  map<string, int>::iterator iter;
  for (iter = mp.begin(); iter != mp.end(); iter++) {
    if (iter->second >= 1)
      jsq++;
  }
  cout << jsq;
  return 0;
}
Problem p02701 (C++) — buggy submission, verdict: Runtime Error

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

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

  vector<string> s(n);
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }

  set<string> num;
  for (int j = 0; j < n; j++) {
    num.insert(s[j]);
  }

  cout << num.size() << endl;
}

Error: WA

Fixed submission:

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

int main() {
  int N;
  cin >> N;
  vector<string> S(200000);
  for (int i = 0; i < N; i++) {
    cin >> S.at(i);
  }

  sort(S.begin(), S.end());

  int sum = N;
  for (int i = 0; i < N; i++) {
    if (S.at(i) == S.at(i + 1)) {
      sum--;
    } else {
      sum = sum;
    }
  }

  cout << sum << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main(void) {
  int N;
  cin >> N;
  vector<string> items(N);
  for (int i = 0; i < N; i++) {
    cin >> items[i];
  }
  set<string> kinds(items.begin(), items.end());
  cout << kinds.size() << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

int main(void) {
  int N, count = 0;
  cin >> N;
  string item;
  vector<string> items;
  for (int i = 0; i < N; i++) {
    cin >> item;
    auto itr = find(items.begin(), items.end(), item);
    if (itr == items.end()) {
      count++;
      items.push_back(item);
    }
  }
  cout << count << endl;
  return 0;
}
Problem p02701 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <set>
#include <string>
using namespace std;
int main() {
  int N;
  cin >> N;
  std::string S;
  set<std::string> list;

  while (N--) {
    cin >> S;
    list.insert(S);
  }

  cout << list.size() << endl;

  return 0;
}


Error: -6
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc


Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
  int N;
  vector<std::string> S(N);
  cin >> N;

  for (int i = 0; i < N; i++) {
    cin >> S[i];
  }

  int cnt = 1;

  for (int i = 0; i < N - 1; i++) {
    if (S[i] != S[i + 1]) {
      cnt++;
    }
  }

  cout << cnt << endl;
  return 0;
}
Problem p02701 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <string>
using namespace std;
int main(void) {
  int i, cnt, n;
  string a[200000];
  scanf("%d", &n);
  for (i = 0; i < n; i++)
    cin >> a[i];
  sort(a, a + n);
  cnt = 1;
  for (i = 1; i < n; i++) {
    if (a[i] != a[i - 1])
      cnt++;
  }
  cout << cnt << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <string>
using namespace std;
int main(void) {
  int i, cnt, n;
  string a[100000];
  scanf("%d", &n);
  for (i = 0; i < n; i++)
    cin >> a[i];
  sort(a, a + n);
  cnt = 1;
  for (i = 1; i < n; i++) {
    if (a[i] != a[i - 1])
      cnt++;
  }
  cout << cnt << endl;
  return 0;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<string> vec(N);
  int cnt = N;
  if (N > 1) {
    for (int i = 0; i < N; i++) {
      cin >> vec.at(i);
    }
    sort(vec.begin(), vec.end());
    for (int i = 0; i < N - 1; i++) {
      if (vec.at(i) == vec.at(i + 1))
        cnt--;
    }
    cout << cnt;
  } else
    cout << N;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<string> vec(N);
  vector<string> lib;

  if (N == 1)
    cout << N;
  else {
    cin >> vec.at(0);
    lib.push_back(vec.at(0));
    for (int i = 1; i < N; i++) {
      cin >> vec.at(i);
      bool AAA = false;
      for (int j = 0; j < lib.size(); j++) {
        if (vec.at(i) == lib.at(j)) {

          AAA = true;
          break;
        }
      }

      if (AAA)
        continue;
      else
        lib.push_back(vec.at(i));
    }
    cout << lib.size();
  }
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
  int t;
  cin >> t;
  string arr[t];
  ;
  for (int i = 0; i < t; i++)
    cin >> arr[i];

  sort(arr, arr + t);

  int count = 0;
  for (int i = 0; i < t - 1; i++) {
    if (arr[i] == arr[i + 1])
      count++;
  }

  cout << t - count;

  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
  int t;
  cin >> t;
  string arr[t];
  ;
  for (int i = 0; i < t; i++)
    cin >> arr[i];

  int count = 0;
  for (int i = 0; i < t; i++) {
    if (arr[i] != "NULL") {
      for (int j = i + 1; j < t; j++) {
        if (arr[i] == arr[j]) {
          count++;
          arr[j] = "NULL";
        }
      }
    } else
      continue;
  }
  cout << t - count;
  return 0;
}
Problem p02701 (C++) — buggy submission, verdict: Runtime Error

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

int asc(const void *a, const void *b) {
  char *left_char = (char *)a;
  char *right_char = (char *)b;
  return strcmp(left_char, right_char);
}

int main() {
  int n, i, j, c = 1;
  scanf("%d", &n);
  char s[200001][12];
  for (i = 0; i < n; i++) {
    scanf("%11s", s[i]);
  }
  // for(i=0;i<n;i++){ printf("%s\\n",s[i]); }
  qsort(s, n, sizeof(*s), asc);
  // for(i=0;i<n;i++){ printf("%s\\n",s[i]); }
  for (i = 0; i < n - 1; i++) {
    if (strcmp(s[i], s[i + 1]) != 0) {
      c++;
    }
  }
  printf("%d", c);
  return 0;
}

Error: WA

Fixed submission:

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

int asc(const void *a, const void *b) {
  char *left_char = (char *)a;
  char *right_char = (char *)b;
  return strcmp(left_char, right_char);
}

int main() {
  int n, i, j, c = 1;
  scanf("%d", &n);
  char s[200001][10];
  for (i = 0; i < n; i++) {
    scanf("%s", s[i]);
  }
  // for(i=0;i<n;i++){ printf("%s\\n",s[i]); }
  qsort(s, n, 11, asc);
  // for(i=0;i<n;i++){ printf("%s\\n",s[i]); }
  for (i = 0; i < n - 1; i++) {
    if (strcmp(s[i], s[i + 1]) != 0) {
      c++;
    }
  }
  printf("%d", c);
  return 0;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <list>
#include <sstream>
#include <stdio.h>
#include <string>
#include <unordered_set>
#include <valarray>
#include <vector>
using namespace std;

int main(void) {
  long long DataSize = 0;
  long long int Count = 0;

  std::unordered_set<std::string> Datas;

  std::string Tmp;

  cin >> DataSize >> Tmp;
  Datas.emplace(Tmp);
  Count++;

  for (int i = 1; i < DataSize; i++) {
    cin >> Tmp;
    Datas.emplace(Tmp);
  }

  cout << Datas.size() << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <list>
#include <sstream>
#include <stdio.h>
#include <string>
#include <valarray>
#include <vector>
using namespace std;

int main(void) {
  long long DataSize = 0;
  long long int Count = 0;

  std::list<string> Datas;

  std::string Tmp;

  cin >> DataSize >> Tmp;
  Datas.emplace_back(Tmp);
  Count++;

  for (int i = 1; i < DataSize; i++) {
    cin >> Tmp;

    if (std::find(Datas.begin(), Datas.end(), Tmp) == Datas.end()) {
      Datas.emplace_back(Tmp);
      Count++;
    }
  }

  cout << Count << endl;

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

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;
using Vec = vector<int>;
using Graph = vector<vector<int>>;
int main() {

  int n;
  cin >> n;
  vector<string> s(n);

  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  sort(s.begin(), s.end());
  int count = 0;
  for (int i = 0; i < n - 1; i++) {
    if (s[i] == s[i + 1]) {
      count++;
    }
  }
  cout << n - count << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  int N, count;
  count = 0;
  cin >> N;
  string vec[N];
  for (int i = 0; i < N; i++) {

    cin >> vec[i];

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

      if (vec[i] == vec[j]) {
        count++;
        break;
      }
    }
  }
  cout << N - count << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<string> S(N);
  for (int i = 0; i < N; i++) {
    cin >> S.at(i);
  }
  sort(S.begin(), S.end());
  int count = N;
  for (int i = 1; i < N; i++) {
    if (S.at(i - 1) == S.at(i)) {
      count--;
    }
  }
  cout << count << endl;
}

Error: -6
terminate called after throwing an instance of 'std::out_of_range'
  what():  vector::_M_range_check: __n (which is 3) >= this->size() (which is 3)


Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<string> S(N);
  for (int i = 0; i < N; i++) {
    cin >> S.at(i);
  }
  sort(S.begin(), S.end());
  int count = N;
  for (int i = 0; i < N; i++) {
    if (S.at(i) == S.at(i + 1)) {
      count--;
    }
  }
  cout << count << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;
int main() {
  long long n, ans, count;
  string buf;
  std::vector<string> s;
  long long i = 0;
  long long mod = 1000000007;

  ans = 0;
  cin >> n;

  while (i < n) {
    cin >> buf;
    s.push_back(buf);
    i++;
  }
  std::sort(s.begin(), s.end());
  s.erase(std::unique(s.begin(), s.end()), s.end());

  cout << s.size();
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
int main() {
  long long n, ans, count;
  string buf;
  std::vector<string> s;
  long long i = 0;
  long long mod = 1000000007;

  ans = 0;
  cin >> n;
  cin >> buf;
  s.push_back(buf);

  while (i < n - 1) {
    int j = 0;
    cin >> buf;
    count = 0;
    while (j < s.size()) {
      if (buf == s[j]) {
        count++;
      }
      j++;
    }
    if (count == 0) {
      s.push_back(buf);
    }
    i++;
  }

  cout << s.size();
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int i, j, n, c;
string s;
map<string, int> a;
int main() {
  for (cin >> n; i < n; i++) {
    cin >> s;
    a[s]++;
  }
  cout << a.size();
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int i, j, n, c;
string s, a[200000];
bool f;
int main() {
  for (cin >> n; i < n; i++) {
    cin >> s;
    if (c == 0)
      a[0] = s, c++;
    for (f = true, j = 0; j < c; j++) {
      if (s.compare(a[j]) == 0) {
        f = false;
        break;
      }
    }
    if (f)
      a[c] = s, c++;
  }
  cout << c;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded


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

int main() {
  int n;
  cin >> n;
  string a[n];
  ;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  unordered_set<string> s;
  int count = 0;
  for (int i = 0; i < n; i++) {

    if (s.find(a[i]) == s.end()) {
      s.insert(a[i]);
      count++;
    }
  }

  cout << count;
  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  int n;
  cin >> n;
  string a[n];
  ;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int count = 1;
  for (int i = 1; i < n; i++) {
    int j = 0;
    for (j = 0; j < i; j++)
      if (a[i] == a[j])
        break;

    if (i == j)
      count++;
  }
  cout << count;
  return 0;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

  int ans = n;

  vector<string> vec(n);
  for (int i = 0; i < n; i++) {
    cin >> vec.at(i);
  }

  sort(vec.begin(), vec.end());

  for (int j = 0; j < n - 1; j++) {
    if (vec.at(j) == vec.at(j + 1))
      ans--;
  }

  cout << ans << endl;
}

Error: TLE

Fixed submission:

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

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

  int count = 0;
  vector<string> vec(n);
  for (int i = 0; i < n; i++) {
    cin >> vec.at(i);
    for (int j = 0; j < i; j++) {
      if (vec.at(i) == vec.at(j)) {
        count--;
        break;
      }
    }
    count++;
  }
  cout << count << endl;
}