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

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

typedef unsigned long long ull;
#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define range(a) a.begin(), a.end()
#define endl "\\n"
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl
const ull mod = 1e9 + 7;

int main(void) {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int N;
  cin >> N;
  string S;
  set<string> st;
  while (N--) {
    cin >> S;
    st.insert(S);
  }

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

  return 0;
}

Error: TLE

Fixed submission:

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

int main(void) {
  unsigned int count = 1;
  unsigned int N;
  vector<unsigned int> var(N);
  string text;
  cin >> N;
  vector<string> v(N);
  for (unsigned int i = 0; i < N; i++) {
    cin >> v[i];
    for (unsigned int j = 0; j < i; j++) {
      if (v[i] == v[j])
        break;
      else if (j == i - 1)
        count++;
    }
  }

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


Error: TLE

Fixed submission:

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

bool sin(vector<string> &gacha, int x) {
  for (int i = 0; i < x; i++) {
    if (gacha.at(i) == gacha.at(x))
      return false;
  }
  return true;
}

int main() {
  int N;
  cin >> N;
  vector<string> gacha(N);
  for (int i = 0; i < N; i++)
    cin >> gacha.at(i);
  int count = 1;
  for (int i = 1; i < N; i++) {
    if (sin(gacha, i))
      count++;
  }
  cout << count << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

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

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

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

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

  vector<string> S(N);
  int count = 0;
  bool flag = 0;

  for (int i = 0; i < N; i++) {
    cin >> S.at(i);
    //    cout << "A";
    for (int j = 0; j < i; j++) {
      if (S.at(i) == S.at(j)) {
        flag = 1;
        //        cout << "B";
      }
    }
    if (flag == 0) {
      count++;
      //      cout << "C";
    }
    flag = 0;
  }

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

#include <iostream>
#include <map>
#include <set>
#include <string>
using namespace std;
int main() {
  int n;
  cin >> n;
  int cnt = n;
  map<string, bool> m;
  for (int i = 1; i <= n; i++) {
    string s;
    cin >> s;
    if (m.count(s)) {
      cnt--;
    } else {
      m.insert(make_pair(s, true));
    }
  }
  cout << cnt << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <set>
#include <string>
using namespace std;
int main() {
  set<string> st;
  int n;
  string s[100005];
  cin >> n;
  int cnt = n;
  for (int i = 1; i <= n; i++) {
    cin >> s[i];
    int l = st.size();
    st.insert(s[i]);
    if (st.size() == l) {
      cnt--;
    }
  }
  cout << cnt << endl;
  return 0;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

int main(void) {
  int N, i;

  cin >> N;

  vector<string> S(N);

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

  set<string> aaa;

  for (i = 0; i < N; i++) {
    aaa.insert(S.at(i));
  }

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

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main(void) {
  int N, i, j, ans;
  bool check;
  ans = 0;

  cin >> N;

  vector<string> S(N);
  vector<string> C(N);

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

  for (i = 0; i < N; i++) {
    check = true;
    for (j = 0; j < ans + 1; j++) {
      if (S.at(i) == C.at(j)) {
        check = false;
        break;
      }
    }
    if (check) {
      C.at(ans) = S.at(i);
      ans++;
    }
  }

  cout << ans << endl;

  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 < n; i++)
typedef long long ll;
typedef vector<string> vec;
int main() {
  int n, ans = 1;
  cin >> n;
  vec s(n);
  rep(i, n) cin >> s[i];

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

  for (int i = 1; i < n; i++) {
    if (s[i] != s[i - 1])
      ans++;
  }

  cout << ans << endl;
}

Error: 0

Fixed submission:

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

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

  for (int i = 0; i < n; i++) {
    if (s[i] != s[i - 1])
      ans++;
  }

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

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

int main() {
  int N;
  string S[200000];
  cin >> N;

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

  sort(S, S + N); // Sをソート

  int counter = 1;
  bool res = true;
  for (int i = 1; i < N; ++i) {
    if (S[i] != S[i - 1])
      ++counter;
  }
  cout << counter << endl;
}

Error: TLE

Fixed submission:

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

// C 10の4乗と5乗をまちがえてるよ
int main() {
  int N;
  string S[200000];
  cin >> N;

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

  int counter = 0;
  bool res = true; // 初期値はtrue
  for (int i = 0; i < N; ++i) {
    res = true;
    for (int j = 0; j < i; ++j) {
      if (S[i] == S[j]) {
        res = false;
        break;
      }
    }
    if (res)
      ++counter;
  }
  cout << counter << endl;
  return 0;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

Error: TLE

Fixed submission:

#include <cstring>
#include <iostream>
using namespace std;
#define int long long
long long n;
char a[200010][15];
signed main() {
  bool flag = 0;
  bool flag2 = 0;
  cin >> n;
  int t = 0;
  for (int i = 1; i <= n; i++) {
    string s;
    cin >> s;
    for (int j = 0; j <= s.size(); j++) {
      a[i][j] = s[j];
    }
    for (int k = 0; k < i; k++) {
      for (int p = 0; p < 10; p++) {
        if (a[k][p] == a[i][p])
          flag = 1;
        if (a[k][p] != a[i][p]) {
          flag = 0;
          break;
        }
      }
      if (flag == 1)
        flag2 = 1;
    }
    if (!flag2)
      t += 1;
  }
  cout << t;
}
Problem p02701 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
using lli = long long int;
using vi = vector<int>;
using vs = vector<string>;
using gi = greater<int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define soao(c) sort((c).begin(), (c).end())       // 昇順
#define sodo(c) sort((c).begin(), (c).end(), gi()) // 降順
#define rev(c) reverse((c).begin(), (c).end())

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

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

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

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using lli = long long int;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, n) for (int i = 1; i < (int)(n); i++)
using vi = vector<int>;
using vs = vector<string>;
using gi = greater<int>;
#define soao(c) sort((c).begin(), (c).end())       // 昇順
#define sodo(c) sort((c).begin(), (c).end(), gi()) // 降順
#define rev(c) reverse((c).begin(), (c).end())

int main() {
  int n;
  cin >> n;
  vs result;
  string unknown;

  rep(i, n) {
    cin >> unknown;
    rep(j, i) {
      if (result.at(j) == unknown) {
        goto next;
      }
    }
    result.push_back(unknown);
  next:;
  }

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

#include <bits/stdc++.h>
using namespace std;
#define ll long long
map<string, int> a;
int main() {
  int n, num = 0;
  string s;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> s;
    if (a[s] == 0) {
      num++;
      a[s]++;
    } else
      a[s]++;
  }
  cout << num;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
int n, i, j, k, x, flag, a[200010];
string s[200010];
int main() {
  cin >> n;
  x = n;
  for (i = 0; i < n; i++) {
    cin >> s[i];
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < n - i; j++) {
      if (s[i].size() != s[j + i + 1].size())
        continue;
      for (k = 0; k < s[i].size(); k++)
        if (s[i][k] != s[i + j + 1][k])
          break;
      if (k == s[i].size() && (a[i] == false || a[i + j] == false))
        x--;
      a[i] = true;
      a[i + j] = true;
    }
  }
  cout << x;
  return 0;
}
Problem p02701 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<string> str(n);
  rep(i, n) cin >> str[i];

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

  int ans = n;
  rep(i, n - 1) {
    if (str[i] == str[i + 1]) {
      ans--;
    }
  }
  cout << ans << endl;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<string> str(n);
  rep1(i, n) {
    string s;
    cin >> s;
    str[i] = s;
  }

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

  rep(i, n) { cout << str[i]; }
  int ans = n;
  rep(i, n - 1) {
    if (str[i] == str[i + 1]) {
      ans--;
    }
  }
  cout << ans << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#include "bits/stdc++.h"
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define INF 1e+9

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

  return 0;
}

Error: TLE

Fixed submission:

#include "bits/stdc++.h"
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define INF 1e+9

int main() {
  int n;
  cin >> n;
  vector<string> s;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    string ss;
    cin >> ss;
    if (find(s.begin(), s.end(), ss) == s.end()) {
      s.push_back(ss);
      ans++;
    }
  }

  cout << ans << endl;

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

#include <bits/stdc++.h>

typedef long long ll;
typedef unsigned long long ull;

#define SIZE_OF_ARRAY(array) (sizeof(array) / sizeof(array[0]))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define AA(i) cout << i << endl;
#define AS(i) cout << i << " ";

const int INF = 1001001001;

using namespace std;

int main() {

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

  rep(i, n) { cin >> a[i]; }

  int ans = 0;

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

  string now = a[0];
  ans++;
  rep(i, n) {
    if (a[i] != now) {
      now = a[i];
      ans++;
    }
  }

  AA(ans);
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <vector>

using namespace std;
const double PI = 3.14159265358979323846;

#define SIZE_OF_ARRAY(array) (sizeof(array) / sizeof(array[0]))

int main() {

  int N;

  cin >> N;

  vector<string> v;

  int count = 0;

  string tmp;
  for (int i = 0; i < N; i++) {
    cin >> tmp;
    bool is = true;

    for (int j = 0; j < v.size(); j++) {
      if (tmp.compare(v[j]) == 0) {
        is = false;
        break;
      }
    }

    if (is) { /*
              int num = 0;
              for (int i = 0; i < N; i++) {
                      if (v[i].compare("") == 0){
                              num = i;
                              break;
                      }
              }
*/
      v.push_back(tmp);
    }
  }

  count = v.size();
  /*
          for (int i = 0; i < N; i++) {
                  if (v[i].compare("") != 0){ count++;
                  }
          }
  */
  cout << count << endl;
}

/*
        string v[N] = {""};

        string tmp;
        int count = 0;
        for (int i = 0; i < N; i++) {
                cin >> tmp;

                bool is = true;
                for (int i = 0; i < N; i++) {
                        if(v[i].compare(tmp) == 0) { is = false; break;}
                }

                if(is) {
                        int num = 0;
                        for (int i = 0; i < N; i++) {
                                if (v[i].compare("") == 0){
                                        num = i;
                                        break;
                                }
                        }

                        v[num] = tmp;
                }
        }

        for (int i = 0; i < N; i++) {
                if (v[i].compare("") != 0){ count++;
                }
        }

        cout << count << endl;
        */
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <map>
#include <stdio.h>
#include <string.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)

using namespace std;
using ll = long long;

int main() {
  // 整数の入力
  std::map<std::string, int> mp;
  int a;
  cin >> a;
  rep(i, a) {
    string c;
    cin >> c;
    mp[c] = 0;
  }

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

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <stdio.h>
#include <string.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)

using namespace std;
using ll = long long;

bool search(string a, string *data_base, int data_num) {
  if (data_num == 0) {
    return false;
  }
  rep(i, data_num) {
    if (!a.compare(data_base[i])) {
      return true;
    }
  }

  return false;
}

int main() {
  // 整数の入力
  int a;
  cin >> a;
  string data_base[10][a];
  // スペース区切りの整数の入力
  int data_cnt[10] = {0};

  string c;

  rep(i, a) {
    cin >> c;
    int c_size = c.length();
    int d = c_size - 1;
    if (!search(c, data_base[d], data_cnt[d])) {
      data_base[d][data_cnt[d]] = c;
      data_cnt[d] += 1;
    }
  }

  int sum = 0;
  rep(i, 10) { sum += data_cnt[i]; }
  cout << sum << endl;
  return 0;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <assert.h>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)
using ll = long long;
const int inf = 1e9 + 7;

int main() {
  int n, cnt;
  bool a = true;
  vector<string> s;
  string ss;
  cin >> n;
  cnt = n;
  rep(i, n) {
    cin >> ss;
    s.push_back(ss);
  }
  sort(s.begin(), s.end());
  rep(i, n - 1) {
    if (s[i] == s[i + 1])
      cnt--;
  }
  cout << cnt << endl;
  ;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <assert.h>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)
using ll = long long;
const int inf = 1e9 + 7;

int main() {
  int n, cnt = 1;
  bool a = true;
  vector<string> s;
  string ss;
  cin >> n;
  rep(i, n) {
    cin >> ss;
    if (i > 0) {
      rep(j, cnt) {
        // cout << ss << ' ' << i << ' ' << s[j] << ' ' << j << endl;

        if (ss == s[j]) {
          // cout << "Yes" << endl;
          a = false;
          break;
        }
      }
      if (a == true) {
        cnt++;
        s.push_back(ss);
      }
      a = true;
    } else
      s.push_back(ss);
  }
  cout << cnt << endl;
  ;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int a[N], b[N];
map<string, int> memo;
int main() {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(0);
  int n;
  cin >> n;
  while (n--) {
    string s;
    cin >> s;
    memo[s]++;
  }
  int ans = 0;
  for (auto it = memo.begin(); it != memo.end(); it++) {
    if (it->second > 0)
      ans++;
  }
  cout << ans;
  return 0;
}


Error: TLE

Fixed submission:

#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
char a[200000 + 10][20], b[200000 + 10][20];
int main() {
  int n;
  scanf("%d", &n);
  int i = 0;
  getchar();
  for (int i = 0; i < n; i++) {
    scanf("%s", &a[i]);
  }
  strcpy(b[0], a[0]);
  int cnt = 1, k = 0;
  for (int d = 0; d < n; d++)
    for (int i = d + 1; i < n; i++) {
      if (!strcmp(a[i], a[d]))
        continue;
      else {
        for (int j = 0; j < k; j++) {
          if (!strcmp(a[i], b[j]))
            cnt--;
        }
        cnt++;
        strcpy(b[++k], a[i]);
      }
    }

  printf("%d\\n", cnt);
  return 0;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded


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

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

Error: TLE

Fixed submission:


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

int main() {
  int n;
  cin >> n;
  vector<string> sn;
  string s;
  cin >> s;
  sn.push_back(s);
  for (size_t i = 0; i < n - 1; i++) {
    cin >> s;
    int same = 0;
    for (size_t i = 0; i < sn.size(); i++) {
      if (sn[i] == s) {
        same = 1;
      }
    }
    if (same == 0) {
      sn.push_back(s);
    }
  }
  cout << sn.size() << endl;
  return 0;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>

using namespace std;

int gcd(int p, int q) {
  if (p % q == 0)
    return q;
  return gcd(q, p % q);
}

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

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

  for (int i = 0; i < n - 1; i++) {
    if (s[i] != s[i + 1]) {
      count++;
    }
  }

  cout << count;

  return 0;
}


Error: TLE

Fixed submission:

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

int ri() {
  int n;
  cin >> n;
  return n;
}

int main() {
  int n, count = 0;
  n = ri();
  vector<string> A(n);

  for (int i = 0; i < n; i++)
    cin >> A[i];
  count = 1;
  bool b = false;

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

    for (int j = i + 1; j < n; j++) {
      if (A[i] == A[j]) {
        A[j] = A[n - 1];
        j--;
        A[n - 1] = "\\0";
        n = n - 1;
      }
    }
  }

  cout << n;

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

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

int main() {
  int N, P, j;
  string A;
  cin >> N;
  map<string, int> S;
  for (int i = 0; i < N; i++) {
    cin >> A;
    S[A]++;
  }
  cout << S.size() << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  int N, P = 1, j;
  cin >> N;
  vector<string> S(N);
  cin >> S.at(0);
  for (int i = 1; i < N; i++) {
    j = 0;
    cin >> S.at(i);
    while (1) {
      if (i == j) {
        P++;
        break;
      }
      if (S.at(i) != S.at(j)) {
        j++;
        continue;
      }
      break;
    }
  }
  cout << P << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n, i;
  string s;
  vector<string> items;
  items.clear();

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


Error: TLE

Fixed submission:

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

int main() {
  int n, i, ans = 0;
  string s;
  vector<string> items;

  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> s;
    auto it = find(items.begin(), items.end(), s);
    if (it == items.end()) {
      items.emplace_back(s);
      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, X;
  string S, A;
  cin >> N;
  X = 1;
  vector<string> vec;
  for (int i = 0; i < N; i++) {
    cin >> S;
    vec.push_back(S);
  }
  sort(vec.begin(), vec.end());
  A = vec.at(0);
  for (int j = 1; j < vec.size(); j++) {
    if (A == vec.at(j)) {

    } else {
      A = vec.at(j);
      X++;
    }
  }
  cout << X << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, X;
  string S;
  cin >> N;
  vector<string> vec;
  cin >> S;
  vec.push_back(S);
  for (int i = 0; i < N; i++) {
    cin >> S;

    for (int j = 0; j < vec.size(); j++) {
      if (S == vec.at(j)) {
        break;
      } else if (j == vec.size() - 1) {
        vec.push_back(S);
      }
    }
  }
  cout << vec.size() << endl;
}
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 < n; i++)

int main() {
  int n;
  cin >> n;
  vector<string> items(n);
  rep(i, n) cin >> items.at(i);
  sort(items.begin(), items.end());
  int ans = 1;
  rep(i, n - 1) {
    if (items.at(i) == items.at(i + 1))
      continue;
    ans++;
  }
  cout << ans << endl;
}

// TLE

Error: TLE

Fixed submission:

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

int main() {
  int n;
  cin >> n;
  vector<string> items = {};
  rep(i, n) {
    string s;
    cin >> s;
    items.push_back(s);
    rep(j, items.size() - 1) {
      if (items.at(j) == s) {
        items.pop_back();
        break;
      }
    }
  }
  cout << items.size() << endl;
}