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

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int N;
  cin >> N;
  map<string, bool> s;
  rep(i, N) {
    string s1;
    cin >> s1;
    s[s1] = true;
  }
  cout << s.size();

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int N;
  cin >> N;
  vector<string> s(N);
  vector<string> s2(0);
  rep(i, N) {
    cin >> s[i];
    bool flag = false;
    for (int j = 0; j < (int)s2.size(); j++) {
      if (s2[j] == s[i]) {
        flag = true;
        break;
      }
    }
    if (!flag) {
      s2.push_back(s[i]);
    }
  }
  cout << s2.size();

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

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

int main() {
  int n, flag = 0;
  cin >> n;
  vector<string> s(n);
  string tmp;

  for (int i = 0; i < n; i++) {
    cin >> s.at(i);
  }
  sort(s.begin(), s.end());
  s.erase(unique(s.begin(), s.end()), s.end());
  cout << s.size() << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  int n, flag = 0;
  cin >> n;
  vector<string> s;
  string tmp;

  for (int i = 0; i < n; i++) {
    cin >> tmp;
    auto itr = find(s.begin(), s.end(), tmp);
    if (itr == s.end())
      s.push_back(tmp);
    flag = 0;
  }
  cout << s.size() << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n;
  set<string> s;
  string sin;
  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> sin;
    s.insert(sin);
  }
  cout << s.size() << endl;
}


Error: TLE

Fixed submission:

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

int main() {
  int n, syurui = 0, ans = 0;
  string sin;
  vector<string> s(n);
  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> sin;
    auto result = std::find(s.begin(), s.end(), sin);
    if (result == s.end()) {
      ans++;
      s.at(i - syurui) = sin;
    } else {
      syurui++;
    }
  }
  cout << ans;
  return 0;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, j, i, ans = 1;
  set<string> s;
  string str;
  cin >> n;
  for (int k = 0; k < n; k++) {
    cin >> str;
    s.insert(str);
  }

  /* vector<string>s;
   cin>>str;
   string str;
   s.push_back(str);
   {
       cin>>str;

       for(i=0; i<s.size(); i++)
       {
           if(s.at(i)==str)
           {
               break;
           }
           else
           {
               s.push_back(str);
               //ans++;
               break;
           }
       }

   }
   */
  cout << s.size() << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, j, i, ans = 0;
  vector<string> s;
  cin >> n;
  string str;
  while (n--) {
    cin >> str;
    s.push_back(str);
  }
  // cout<<endl;
  for (i = 0; i < s.size() - 1; i++) {
    for (j = i + 1; j < s.size(); j++)
      // cout<<s.at(i)<<endl;
      if (s.at(i) == s.at(j))
        s.at(j) = "0";
  }
  for (i = 0; i < s.size(); i++) {
    if (s.at(i) == "0")
      ;
    else
      ans++;
  }
  cout << ans << 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;
  map<string, int> a;
  int n = 0;
  for (int i; i < N; i++) {
    string S;
    cin >> S;
    if (i == 0) {
      a[S] = 1;
      n += 1;
    } else {
      if (a.count(S)) {
      } else {
        a[S] = 1;
        n += 1;
      }
    }
  }
  cout << n << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  int N;
  cin >> N;
  map<int, string> a;
  int n = 0;
  for (int i; i < N; i++) {
    string S;
    cin >> S;
    // cout << S << endl;
    if (i == 0) {
      a[0] = S;
      n += 1;
    } else {
      // cout << i;
      int j = 0;
      while (true) {
        if (a[j] == S) {
          break;
        }
        if (j == i - 1) {
          n += 1;
          break;
        }
        j += 1;
      }
    }
  }
  cout << n << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Runtime Error

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

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

  set<string> g;
  for (int i = 0; i < N; i++) {
    string s;
    cin >> s;
    g.insert(s);
  }

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


Error: 0

Fixed submission:

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

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

  set<string> g;

  for (int i = 0; i < N; i++) {
    g.insert(s[i]);
  }

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

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

int main() {
  int N;
  cin >> N;
  string st;
  set<string> s;

  for (int i = 1; i <= N; i++) {
    cin >> st;
    s.insert(st);
  }

  cout << s.size();
}

Error: TLE

Fixed submission:

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

int main() {
  int N;
  cin >> N;
  string st;
  bool found = false;
  int stsize = 0;
  int total = 0;

  array<vector<string>, 11> ar;
  vector<string>::iterator it;

  for (int i = 1; i <= N; i++) {
    cin >> st;
    stsize = st.length();

    for (it = ar[stsize].begin(); it != ar[stsize].end(); it++) {
      if (*it == st) {
        found = true;
        break;
      }
    }

    if (found == false) {
      ar[stsize].push_back(st);
    } else {
      found = false;
    }
  }

  for (int i = 1; i <= 10; i++) {
    total = total + ar[i].size();
  }

  cout << total;
}
Problem p02701 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <set>
#include <string>
#include <vector>
using namespace std;
int main() {
  int num;
  string b;
  cin >> num;
  set<string> a;
  for (int i = 0; i < num; i++) {
    cin >> b;
    a.insert(b);
  }
  cout << a.size();
  return 0;
}


Error: WA

Fixed submission:

#include <iostream>
#include <set>
#include <string>
#include <vector>
using namespace std;
int main() {
  int num;
  string b[101];
  cin >> num;
  set<string> a;
  for (int i = 0; i < num; i++) {
    cin >> b[i];
    a.insert(b[i]);
  }
  cout << a.size();
  return 0;
}
Problem p02701 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
int main() {
  int n;
  cin >> n;
  ll cnt = 1;
  vector<string> s(n);
  for (int i; 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))
      cnt++;
  }
  cout << cnt << endl;
}

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


Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
int main() {
  int n;
  cin >> n;
  vector<string> s;
  rep(i, n) cin >> s.at(i);

  sort(s.begin(), s.end());
  int cnt = 1;
  for (int i = 1; i < s.size(); i++) {
    if (s.at(i) == s.at(i - 1))
      cnt++;
  }
  cout << cnt << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#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;
  vector<string> keihin(N);
  map<string, string> kekka;
  for (int i = 0; i < N; i++) {
    cin >> keihin.at(i);
  }
  int x = 0;
  for (int i = 0; i < N; i++) {
    if (!(kekka.count(keihin.at(i)))) {
      kekka[keihin.at(i)] = keihin.at(i);
    }
  }
  cout << kekka.size() << endl;
}


Error: TLE

Fixed submission:

#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#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;
  vector<string> keihin(N);
  queue<string> kekka;
  for (int i = 0; i < N; i++) {
    cin >> keihin.at(i);
  }
  int x = 0;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < i; j++) {
      if (keihin.at(i) == keihin.at(j)) {
        x = 1;
      }
    }
    if (x == 0) {
      kekka.push(keihin.at(i));
    }
    x = 0;
  }
  cout << kekka.size() << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)

using namespace std;

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

  int ans = 1;

  rep(i, n) { cin >> s.at(i); }

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

  string mem = s.at(0);
  for (int i = 1; i < n; i++) {
    if (mem != s.at(i)) {
      ans++;
      mem = s.at(i);
    }
  }

  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  vector<string> s_mem;

  int ans = 0;

  rep(i, n) {
    cin >> s.at(i);
    sort(s.at(i).begin(), s.at(i).end());

    bool mem_flg = false;

    rep(j, (int)s_mem.size()) {
      if (s_mem.at(j) == s.at(i)) {
        mem_flg = true;
        break;
      }
    }
    if (!mem_flg) {
      ans++;
      s_mem.push_back(s.at(i));
    }
  }

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

#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
string s[200005];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> s[i];
  sort(s, s + n);
  int k = 0;
  string a = "";
  for (int i = 0; i < n; i++) {
    if (s[i] == a)
      ;
    else {
      a = s[i];
      k++;
    }
  }
  cout << k;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;
const int N = 2e5 + 10;
int son[N][26], cnt[N], idx;
void insert(char *str) {
  int p = 0;
  for (int i = 0; str[i]; i++) {
    int u = str[i] - 'a';
    if (!son[p][u])
      son[p][u] = ++idx;
    p = son[p][u];
  }
  cnt[p]++;
}
int query(char *str) {
  int p = 0;
  for (int i = 0; str[i]; i++) {
    int u = str[i] - 'a';
    if (!son[p][u])
      return 0;
    p = son[p][u];
  }
  return cnt[p];
}
int n;
int main() {
  cin >> n;
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    char str[15];
    cin >> str;
    if (!query(str))
      insert(str), cnt++;
  }
  cout << cnt;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int N, i, count;
  cin >> N;
  set<string> s;
  string str;
  for (i = 0; i < N; i++) {
    cin >> str;
    s.insert(str);
  }

  count = s.size();

  cout << count << endl;
}

Error: TLE

Fixed submission:

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

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

  count = 0;

  for (i = 0; i < N; i++) {
    if (S[i] != "0") {
      count++;
      for (j = i + 1; j < N; j++) {
        if (S[i] == S[j]) {
          S[j] = "0";
        }
      }
    }
  }

  cout << 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> a(N);
  for (int i = 0; i < N; i++)
    cin >> a.at(i);
  sort(a.begin(), a.end());
  int x = N;
  for (int i = 1; i < N; i++)
    if (a.at(i) == a.at(i - 1))
      x--;
  cout << x << endl;
}


Error: 0

Fixed submission:

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

#include <iostream>
#include <map>
#include <string>
#pragma GCC optimize("Ofast")
using namespace std;

int main() {
  int N;
  string s;
  map<string, int> m;

  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  cin >> N;
  for (int i = 0; i < N; ++i) {
    cin >> s;
    m[s] = 1;
  }
  cout << m.size() << "\\n";
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <iterator>
#include <string>
#include <vector>
#pragma GCC optimize("Ofast")
using namespace std;

int main() {
  int N;
  string s;
  vector<string> ss;
  vector<string>::iterator it;
  vector<int>::difference_type index;

  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  cin >> N;
  cin >> s;
  ss.push_back(s);
  for (int i = 1; i < N; ++i) {
    cin >> s;
    it = find(ss.begin(), ss.end(), s);
    if (distance(ss.begin(), it) == ss.size()) {
      ss.push_back(s);
    }
  }
  cout << ss.size() << "\\n";
}
Problem p02701 (C++) — buggy submission, verdict: Runtime Error

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

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

  sort(vec.begin(), vec.end());
  int count = N;

  for (int i = 0; i < N - 1; i++) {

    if (vec.at(i) == vec.at(i + 1))
      count--;
  }
  cout << count << endl;
}


Error: WA

Fixed submission:

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

int main() {
  int N;
  vector<string> S(11);
  cin >> N;
  for (int i = 0; i < 11; i++) {
    S.at(i);
  }
  int count = N;
  sort(S.begin(), S.end());

  for (int i = 0; i < N - 1; 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() {
  int n;
  cin >> n;
  set<string> s;
  for (int i = 0; i < n; i++) {
    string j;
    cin >> j;
    s.insert(j);
  }
  cout << s.size() << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<string> in(n);
  for (int i = 0; i < n; i++) {
    cin >> in.at(i);
  }
  vector<string> out(0);
  for (int i = 0; i < n; i++) {
    int flag = 0;
    for (int j = 0; j < out.size(); j++) {
      if (out.at(j) == in.at(i)) {
        flag = 1;
        break;
      }
    }
    if (flag == 0) {
      out.push_back(in.at(i));
    }
  }
  /*for(int i =0;i<out.size();i++){
      cout << out.at(i)<<endl;
}*/
  cout << out.size() << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  string s;
  cin >> n;
  set<string> dai;
  for (int t = 0; t < n; t++) {
    cin >> s;
    dai.insert(s);
  }
  cout << dai.size();
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int n, ma, ba = 0;
  string b[200001];
  cin >> n;
  for (int t = 1; t <= n; t++) {
    cin >> b[t];
    // cout<<b[t];
    ma = 0;
    for (int i = 1; i < t; i++) {
      if (b[t] != b[i]) {
        ma++;
      }
    }
    if (ma == t - 1) {
      ba++;
    }
  }
  cout << ba;
  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 Graph = vector<vector<int>>;

int main(void) {
  ll n;
  cin >> n;
  set<string> st;
  string s;
  for (ll i = 0; i < n; i++) {
    cin >> s;
    st.insert(s);
  }
  cout << st.size() << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <functional>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
// #include <boost/integer/common_factor_rt.hpp> // gcd, lcm
// #include <bits/stdc++.h>

using namespace std;

int main() {
  int n;
  cin >> n;
  string keihin;
  vector<string> itiran;
  for (int i = 0; i < n; i++) {
    cin >> keihin;
    if (i == 0) {
      itiran.push_back(keihin);
      continue;
    }
    bool j = false;
    for (int i = 0; i < itiran.size(); i++) {
      if (!itiran[i].compare(keihin)) {
        j = true;
      }
    }
    if (!j) {
      itiran.push_back(keihin);
    }
  }
  cout << itiran.size() << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int N;
  cin >> N;
  string s;
  int count = 0;
  int max = 0;
  map<string, int> str;
  for (int i = 0; i < N; i++) {
    cin >> s;
    if (str.count(s)) {
      str[s]++;

      continue;
    } else {
      str[s] = 1;
      count++;
    }
  }
  cout << count << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  int N;
  int sum = 0;
  cin >> N;
  vector<string> s(N);
  for (int i = 0; i < N; i++) {
    cin >> s.at(i);
    if (i == 0) {
      sum++;
      continue;
    }

    for (int j = 0; j < i; j++) {
      if (s.at(i) == s.at(j)) {
        break;
      }
      if (j == i - 1) {
        sum++;
      }
    }
  }
  cout << sum << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n;
  cin >> n;
  set<string> gift;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    gift.insert(s);
  }
  cout << gift.size();
}


Error: TLE

Fixed submission:

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

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

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

  int counter = 1;

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

      if (gift.at(i) == gift.at(j)) {
        break;
      }
      if (gift.at(i) != gift.at(j) && j != i - 1) {
        continue;
      }
      if (gift.at(i) != gift.at(j) && j == i - 1) {
        counter++;
      }
    }
  }
  cout << counter << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <iostream>
#include <queue>
#include <string>

#include <algorithm>
#include <fstream>
#include <vector>

using namespace std;

int main(void) {

  int n, res;
  string str;
  vector<string> s;

  res = 1;

  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> str;
    s.push_back(str);
  }

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

  for (int i = 0; i < n - 1; i++) {
    if (s.at(i) != s.at(i + 1)) {
      res++;
    }
  }

  cout << res << endl;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>

#include <algorithm>
#include <fstream>
#include <vector>

using namespace std;

int main(void) {

  long n, res;
  string s[200000];
  vector<string> r;

  res = 0;

  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> s[i];
    if (!i)
      r.push_back(s[i]);

    for (int j = 0; j < r.size(); j++) {
      if (s[i] == r.at(j)) {
        break;
      }
      if (s[i] != r.at(j)) {
        if (j == r.size() - 1) {
          r.push_back(s[i]);
          break;
        }
      }
    }
  }

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

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

string S[200000];

int main() {
  int N;
  set<string> setS;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> S[i];
    setS.insert(S[i]);
  }

  cout << setS.size();
}

Error: TLE

Fixed submission:

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

string S[200000];

int main() {
  int N, a, ans = 0;
  string all = "";
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> S[i];
  }
  for (int i = 0; i < N; i++) {
    a = all.find("," + S[i] + ",");
    if (a == string::npos) {
      all += "," + S[i] + ",";
      ans++;
    }
  }
  cout << ans;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int n, total = 1;
string a;
vector<string> store;

bool comparator(string a, string b) { return a < b; }

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie();
  cout.tie();
  cin >> n;
  while (n--) {
    cin >> a;
    store.push_back(a);
  }
  sort(store.begin(), store.end(), comparator);
  for (int i = 1; i < store.size(); i++) {
    if (store[i] != store[i - 1]) {
      total++;
    }
  }
  cout << total << '\\n';
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int n, total = 0;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie();
  cout.tie();
  string b;
  vector<string> a;
  cin >> n;
  while (n--) {
    cin >> b;
    if (find(a.begin(), a.end(), b) != a.end()) {
      continue;
    } else {
      total++;
      a.push_back(b);
    }
  }
  cout << total << '\\n';
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using LL = long long;
using P = pair<int, int>;

int main() {
  int n;
  cin >> n;
  set<string> S;
  rep(i, n) {
    string a;
    cin >> a;
    S.insert(a);
  }

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


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using LL = long long;
using P = pair<int, int>;

int main() {
  int N;
  cin >> N;
  vector<string> S(N);
  int ans = 0;
  bool ok = true;
  rep(i, N) {
    cin >> S[i];
    rep(j, i) {
      if (S[j] == S[i])
        ok = false;
    }
    if (ok == true)
      ans++;
  }
  cout << ans << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
  int n;
  string s;
  vector<string> ss;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s;
    ss.push_back(s);
  }
  sort(ss.begin(), ss.end());
  ss.erase(unique(ss.begin(), ss.end()), ss.end());
  cout << ss.size() << endl;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
  int a;
  int n;
  bool b;
  string s;
  vector<string> ss;
  cin >> n;
  for (int i = 0; i < n; i++) {
    b = false;
    cin >> s;
    for (auto &ss : ss) {
      if (ss == s) {
        b = true;
        break;
      }
    }
    if (!b) {
      ss.push_back(s);
    }
  }
  cout << ss.size() << endl;
}