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

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll mod = 1000000007;

ll r(ll x, ll y) {
  if (y == 0)
    return 1;
  else if (y % 2 == 0)
    return r(x, y / 2) * r(x, y / 2) % mod;
  else
    return x * r(x, (y - 1) / 2) % mod * r(x, (y - 1) / 2) % mod;
}

int main() {
  int n;
  cin >> n;
  priority_queue<string> q;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    q.push(s);
  }
  int count = 0;
  string s = q.top();
  while (!q.empty()) {
    count++;
    q.pop();
    while (s == q.top() && !q.empty()) {
      q.pop();
    }
    if (!q.empty()) {
      s = q.top();
    }
  }
  cout << count << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll mod = 1000000007;

ll r(ll x, ll y) {
  if (y == 0)
    return 1;
  else if (y % 2 == 0)
    return r(x, y / 2) * r(x, y / 2) % mod;
  else
    return x * r(x, (y - 1) / 2) % mod * r(x, (y - 1) / 2) % mod;
}

int main() {
  int n;
  cin >> n;
  vector<string> s(1);
  int c = 1;
  cin >> s[0];
  for (int i = 1; i < n; i++) {
    string ss;
    cin >> ss;
    bool f = 1;
    int x = s.size();
    for (int j = 0; j < x; j++) {
      if (ss == s[j]) {
        f = 0;
        break;
      }
    }
    if (f) {
      s.push_back(ss);
      c++;
    }
  }
  cout << c << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n;
  int i, j;

  cin >> n;

  int count = 1;

  vector<string> s(n);

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

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

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

  cout << count << endl;

  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  int n;
  int i, j, k;

  cin >> n;

  vector<string> s(n);

  cin >> s[0];

  int key, count = 1;

  k = 0;
  for (i = 1; i < n; i++) {
    k += 1;
    cin >> s[k];
    key = 0;
    for (j = 0; j < k; j++) {
      if (s[k] == s[j]) {
        key = 1;
      }
    }
    if (key == 0) {
      count += 1;
    } else {
      k -= 1;
    }
  }

  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, count;
  count = 1;
  cin >> n;
  vector<string> vec(n);
  for (int i = 0; i < n; i++) {
    cin >> vec.at(i); // 商品の種類を代入する
  }
  sort(vec.begin(), vec.end()); // 多分ここまではOK
  for (int i = 1; i < n; i++) {
    if (vec.at(i) != vec.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> vec(n);
  vector<string> A(1);
  for (int i = 0; i < n; i++) {
    cin >> vec.at(i); // 商品の種類を代入する
  }
  sort(vec.begin(), vec.end()); // 多分ここまではOK
  A.at(0) = vec.at(0);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < A.size(); j++) {
      if (vec.at(i) == A.at(j)) {
        break;
      }
      if (j == A.size() - 1 && vec.at(i) != A.at(j)) {
        A.push_back(vec.at(i));
      }
    }
  }
  cout << A.size() << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

  cin >> N;

  for (int i = 0; i < N; i++) {
    cin >> s;
    if (!(m[s])) {
      m[s]++;
      ans++;
    }
  }

  cout << ans << endl;

  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  int N, left, right, mid, sum = 0;
  vector<string> gacha;
  string s;
  bool kaburi;

  cin >> N;

  for (int i = 0; i < N; i++) {
    kaburi = false;
    cin >> s;
    left = 0;
    right = sum - 1;
    while (left <= right) {
      mid = (left + right) / 2;
      if (s == gacha[mid]) {
        kaburi = true;
        break;
      } else if (s < gacha[mid]) {
        right = mid;
      } else {
        left = mid;
      }
    }
    if (!(kaburi)) {
      gacha.push_back(s);
      sum++;
      sort(gacha.begin(), gacha.end());
    }
  }

  cout << sum << 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> S(N);
  for (int i = 0; i < N; i++) {
    cin >> S.at(i); // S[i]ではなくS.at(i)
  }
  sort(S.begin(), S.end()); // いい感じに並べ替えてくれる書き方なので覚えよう！
  int i = 0, ans = 1;
  for (int j = 1; j < N; j++) {
    if (S.at(i) != S.at(j)) { // 並べ替えておいて、モノがかわったらansをたす
      ans++;
      i = j;
    }
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

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

long long int N;
long long int j = 0;
long long int ans = 0;
long int tmp = 1;

int main() {
  cin >> N;
  string S[N];
  string str;
  for (int i = 0; i < N; i++) {
    tmp = 1;
    cin >> str;
    for (int k = 0; k < j; k++) {
      if (S[k] == str) {
        tmp = 0;
      }
    }
    if (tmp == 1) {
      S[j] = str;
      j++;
    }
    ans += tmp;
  }
  cout << ans << endl;
}
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() {
  ll N;
  string data;
  cin >> N;

  vector<string> All(N);
  rep(i, N) {
    cin >> data;
    All[i] = data;
  }

  sort(All.begin(), All.end());
  All.erase(unique(All.begin(), All.end()), All.end());
  cout << All.size() << endl;
  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() {
  ll N;
  string data;
  cin >> N;

  vector<string> All;
  rep(i, N) {
    cin >> data;
    auto res = find(All.begin(), All.end(), data);
    if (res == All.end()) {
      All.push_back(data);
    }
  }
  cout << All.size() << endl;
  return 0;
}
Problem p02701 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define fr(i, k, n) for (int i = k; i < n; i++)
#define read(x) cin >> x
#define ll long long int
#define mod 1000000007
#define print(x) cout << x << endl
#define pb(x) push_back(x)
#define fastIO                                                                 \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
int main() {
  fastIO;
  int t = 1, n;
  // cin>>t;
  while (t--) {
    cin >> n;
    set<string> s;
    int ans = 0;
    vector<string> arr;
    string input;
    fr(i, 0, n) {
      cin >> input;
      arr.push_back(input);
      if (!s.count(arr[i])) {
        ans++;
        s.insert(arr[i]);
      }
    }

    cout << ans;
  }

  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define fr(i, k, n) for (int i = k; i < n; i++)
#define read(x) cin >> x
#define ll long long int
#define mod 1000000007
#define print(x) cout << x << endl
#define pb(x) push_back(x)
#define fastIO                                                                 \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
int main() {
  fastIO;
  int t = 1, n;
  // cin>>t;
  while (t--) {
    cin >> n;
    set<string> s;
    int ans = 0;
    string arr[100000];
    fr(i, 0, n) {
      cin >> arr[i];
      if (!s.count(arr[i])) {
        ans++;
        s.insert(arr[i]);
      }
    }

    cout << ans;
  }

  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> S;
  for (int i = 0; i < N; i++) {
    string c;
    cin >> c;
    if (!S.count(c)) {
      S[c] = i;
    }
  }
  cout << S.size() << endl;
}

Error: TLE

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);
  }
  int count = 0;
  for (int i = 0; i < N; i++) {
    count++;
    if (i == N - 1) {
      continue;
    }
    for (int j = i + 1; j < N; j++) {
      if (S.at(i) == S.at(j)) {
        count--;
        break;
      }
    }
  }
  cout << count << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Runtime Error

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

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


Error: -11

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int i, j, n, add = 0;
  bool b;
  string s[10000000];
  cin >> n;
  for (i = 0; i < n; i++) {
    b = true;
    cin >> s[i];
    j = 0;
    while (j < i) {
      if (s[i] == s[j]) {
        b = false;
      }
      j++;
    }
    if (b == true) {
      add++;
    }
  }

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

#include <bits/stdc++.h>

using namespace std;

int main(void) {
  int N;
  set<string> prise;
  int count = 0;

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

    if (prise.find(s) == prise.end()) {
      prise.insert(s);
    }
  }
  cout << prise.size() << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main(void) {
  int N;
  string prise[200000];
  int count = 0;

  cin >> N;
  for (int i = 0; i < N; i++) {
    string s;
    cin >> s;
    int j;
    for (j = 0; j < count; j++) {
      if (prise[j] == s)
        break;
    }
    if (j == count) {
      prise[count] = s;
      count++;
    }
  }
  cout << count << endl;

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

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <stdio.h>
#include <vector>

#define REP(i, n, N) for (ll i = (n); i < (N); i++)
// #define RREP(i, n ,N) for(ll i = (N-1); i >= (n); i--)
#define p(s) cout << (s) << endl
#define p2(a, b) cout << (a) << " " << (b) << endl
#define INF 1e9
#define vint vector<int>

using namespace std;
typedef long long ll;

const long long M = 1e9 + 7;

int main() {
  int n;
  cin >> n;
  vector<string> shina(n);
  string s;
  int count = 1;
  REP(i, 0, n) {
    cin >> s;
    shina[i] = s;
  }
  sort(shina.begin(), shina.end());
  REP(i, 0, n - 1) {
    if (shina[i] != shina[i + 1]) {
      count++;
    }
  }

  p(count);
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <stdio.h>
#include <vector>

#define REP(i, n, N) for (ll i = (n); i < (N); i++)
// #define RREP(i, n ,N) for(ll i = (N-1); i >= (n); i--)
#define p(s) cout << (s) << endl
#define p2(a, b) cout << (a) << " " << (b) << endl
#define INF 1e9
#define vint vector<int>

using namespace std;
typedef long long ll;

const long long M = 1e9 + 7;

int main() {
  int n;
  cin >> n;
  deque<string> shina(n);
  string s;
  bool flag = false;
  int count = 0;
  REP(i, 0, n) {
    cin >> s;
    flag = false;
    if (i == 0) {
      shina[count] = s;
      count++;
      continue;
    }
    REP(j, 0, count) {
      if (s == shina[j]) {
        flag = true;
        break;
      }
    }
    if (not flag) {
      shina[count] = s;
      count++;
    }
  }

  p(count);
}
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;

#define LENGTH 200000

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

  vector<string> words;
  rep(i, N) {
    string tmp;
    cin >> tmp;
    words.push_back(tmp);
  }

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

  cout << words.size();
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>

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

using namespace std;

#define LENGTH 200000

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

  string words[LENGTH];

  int count = 0;
  rep(i, N) {
    cin >> words[i];
#if 1
    if (i == 0) {
      count++;
      continue;
    }
#endif
    int is_dupricated = false;
    for (int j = 0; j <= i - 1; j++) {
      // if(i-1 < 0) break;
      if (words[i] == words[j]) {
        is_dupricated = true;
        break;
      }
    }
    if (is_dupricated == false)
      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, kind_num = 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 = 1; i < n; i++) {
    if (s[i - 1] != s[i])
      kind_num++;
  }

  cout << kind_num << endl;
}

Error: TLE

Fixed submission:

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

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

  for (int i = 0; i < n; i++) {
    if (vec.at(i) != " ")
      for (int j = i + 1; j < n; j++) {
        if (vec.at(i) == vec.at(j)) {
          vec.at(j) = " ";
        }
      }
  }
  for (int i = 0; i < n; i++) {
    if (vec.at(i) != " ")
      count++;
  }
  cout << count << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Runtime Error

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

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

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

  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main() {

  int n;
  cin >> n;
  vector<int> dp(10050, 0);
  for (int i = 1; i < 106; i++) {
    for (int j = 1; j < 106; j++) {
      for (int k = 1; k < 106; k++) {

        int temp = i * i + j * j + k * k + i * j + j * k + k * i;

        if (temp <= 10040)
          dp[temp]++;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    cout << dp[i] << endl;
  }
}
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);
  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;
  cin >> N;
  vector<string> S(N);
  for (int i = 0; i < N; i++) {
    cin >> S.at(i);
  }
  vector<string> s;
  int answer = 0;
  for (int i = 0; i < N; i++) {
    if (find(s.begin(), s.end(), S.at(i)) == s.end()) {
      answer++;
      s.emplace_back(S.at(i));
    }
  }
  cout << answer << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <string>
#include <vector>
#define rip(i, n) for (int i = 0; i < n; i++)
#define ll long long
#define lb long double
#define vec vector<int>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<string> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  int kotae = 0;
  for (int i = 0; i < n - 1; i++) {
    if (a[i] != a[i + 1])
      kotae++;
  }
  cout << kotae + 1 << endl;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<string> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int kotae = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (a[i] == a[j]) {
        kotae--;
        break;
      }
    }
    kotae++;
  }
  cout << kotae << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
string c;
vector<string> s;
int n;
int main() {
  scanf("%d", &n);
  while (n--) {
    cin >> c;
    s.push_back(c);
  }
  sort(s.begin(), s.end());
  s.erase(unique(s.begin(), s.end()), s.end());
  printf("%d", s.size());
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <cstring>
using namespace std;
char a[200005][15], c[15];
int n, i, k = 0, j;
int main() {
  scanf("%d", &n);
  scanf("%s", a[0]);
  for (i = 1; i < n; i++) {
    scanf("%s", c);
    for (j = 0; j < i; j++)
      if (strcmp(a[j], c) == 0)
        break;
    if (j == i) {
      k++;
      strcpy(a[k], c);
    }
  }
  printf("%d", k + 1);
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int N;
vector<string> s;

int main() {
  cin >> N;
  s.resize(N);
  for (int i = 0; i < N; i++)
    cin >> s[i];
  sort(s.begin(), s.end());
  int cnt = 1;
  for (int i = 0; i < N - 1; i++) {
    if (s[i] != s[i + 1])
      cnt++;
  }
  cout << cnt << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

int N;
vector<string> s;

int main() {
  cin >> N;
  s.resize(N);
  for (int i = 0; i < N; i++)
    cin >> s[i];
  int cnt = 0;
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      if (s[i] == s[j])
        break;
      if (j == N - 1)
        cnt++;
    }
    if (i == N - 1)
      cnt++;
  }
  cout << cnt << 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 < (int)(n); i++)
#include <set>
int main() {
  int n;
  cin >> n;
  set<string> word;
  rep(i, n) {
    string s;
    cin >> s;
    word.insert(s);
  }

  cout << word.size() << 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;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  int sum = 0;
  rep(i, n) {
    cin >> s.at(i);
    sort(s.begin(), s.end());
    if (s.at(i) != s.at(i + 1)) {
      sum++;
    }
  }
  cout << sum << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  long N, cnt = 0;
  cin >> N;
  vector<string> S(N), ans(N, "A");
  for (int i = 0; i < N; i++) {
    cin >> S[i];
  }
  sort(S.begin(), S.end());
  for (int i = 0; i < N; i++) {
    if (i == 0) {
      cnt++;
    } else if (S[i] != S[i - 1]) {
      cnt++;
    }
  }
  cout << cnt;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;
int main() {
  long N, cnt = 0;
  cin >> N;
  vector<string> S(N), ans(N, "A");
  for (int i = 0; i < N; i++) {
    cin >> S[i];
  }
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (ans[j] == S[i]) {
        break;
      } else if (ans[j] == "A") {
        cnt++;
        ans[j] = S[i];
        break;
      }
    }
  }
  cout << cnt;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main(void) {
  int n;
  int sum = 0;
  cin >> n;
  vector<string> a(n);
  vector<string> b;

  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  set<string> st(a.begin(), a.end());
  cout << st.size();
}

Error: TLE

Fixed submission:

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

int main(void) {
  int n;
  cin >> n;
  vector<string> a(n);
  vector<string> b;

  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  for (int i = 0; i < n; i++) {
    if (count(b.begin(), b.end(), a.at(i)) == 0)
      b.push_back(a.at(i));
  }
  cout << b.size();
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main(void) {
  int N;
  cin >> N;
  vector<string> S;
  string str;
  for (int i = 0; i < N; i++) {
    cin >> str;
    S.push_back(str);
  }
  sort(S.begin(), S.end());
  S.erase(unique(S.begin(), S.end()), S.end());
  cout << S.size() << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

int main(void) {
  int N;
  cin >> N;
  char S[N][10];
  int num = 0;
  for (int i = 0; i < N; i++) {
    cin >> S[i];
    int count = 0;
    if (i > 0) {
      for (int j = 0; j < i; j++) {
        if (strcmp(S[j], S[i]) == 0) {
          count++;
          break;
        }
      }
    }
    if (count == 0)
      num++;
  }
  cout << num << endl;
  return 0;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#include <cstdlib>
#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;
  int ans = 0;
  vector<string> s;
  cin >> n;
  rep(i, n) {
    string input;
    cin >> input;
    s.push_back(input);
  }
  sort(s.begin(), s.end());
  string prev = "";
  rep(i, n) {
    if (s[i] != prev) {
      prev = s[i];
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <cstdlib>
#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;
  int ans = 0;
  cin >> n;
  vector<string> s(n);
  vector<string> l;
  map<string, int> m{};
  int cnt = 0;
  rep(i, n) {
    cin >> s[i];
    auto f = find(l.begin(), l.end(), s[i]);

    if (f != l.end()) {
      ans++;
    } else {
      l.push_back(s[i]);
    }
  }

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

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

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

long long int N;

int main(void) {
  cin >> N;
  vector<string> S(N);
  for (int i = 0; i < N; i++)
    cin >> S[i];
  sort(S.begin(), S.end());
  long long int ans = 1;
  for (int i = 1; i < N; i++) {
    if (S[i].compare(S[i - 1]) != 0)
      ans++;
  }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

long long int N;

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

  long long int ans = 1;
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      if (S[i].compare(S[j]) == 0)
        break;
      if (j == N - 1 && S[i].compare(S[j]) != 0)
        ans++;
    }
  }
  cout << ans << endl;
  return 0;
}