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

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

int main() {
  int n, count = 1;
  cin >> n;
  string t;
  vector<string> s;
  s.reserve(n);

  for (int i = 0; i < n; i++) {
    cin >> t;
    s.emplace_back(t);
  }
  sort(s.begin(), s.end());

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

Error: TLE

Fixed submission:

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

int main() {
  int n;
  cin >> n;
  string t;
  vector<string> s;
  s.reserve(n);
  size_t ix = 0;
  for (int i = 0; i < n; i++) {
    cin >> t;
    ix = 0;
    for (const string &keihin : s) {
      if (keihin == t)
        break;
      ix++;
    }
    if (ix == s.size())
      s.emplace_back(t);
  }
  cout << s.size();
}
Problem p02701 (C++) — buggy submission, verdict: Runtime Error

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

using namespace std;

int main() {
  int N;
  string str;
  cin >> N;
  map<string, int> mp;
  rep(i, N) {
    cin >> str;
    mp[str]++;
  }
  cout << mp.size() << endl;
}

Error: WA

Fixed submission:

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

using namespace std;

int main() {
  int N, i, j, count = 0;
  // string str;
  cin >> N;
  vector<string> S(N), H(N);
  rep(i, N) {
    cin >> S[i];
    j = hash<string>()(S[i]) % (N * 10);
    // while (1)
    //{
    if (H[j] != S[i]) {
      H[j] = S[i];
      ++count;
      break;
    }
    /*
    else
    {
            if (H[j] == S[i])
                    break;
    }
    j = (j + 3) % (N * 10);
}*/
  }
  cout << count;
}
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;

int main() {
  int n, count = 0;
  string copy;
  cin >> n;
  vector<string> v(n);
  rep(i, n) { cin >> v.at(i); }
  sort(v.begin(), v.end());
  rep(i, n) {
    if (i == 0) {
      copy = v.at(i);
      count++;
    } else if (copy != v.at(i)) {
      copy = v.at(i);
      count++;
    }
  }
  cout << count << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  int n;
  string s;
  vector<string> v;
  cin >> n;
  bool exists;
  rep(i, n) {
    cin >> s;
    sort(v.begin(), v.end());
    exists = std::binary_search(v.begin(), v.end(), s);
    if (exists == false) {
      v.push_back(s);
    }
  }
  cout << v.size() << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll, ll> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    pbds;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ll n;
  cin >> n;
  vector<string> v;
  while (n--) {
    string s;
    cin >> s;
    v.pb(s);
  }
  sort(v.begin(), v.end());

  string k = v[0];
  ll ans = 1;
  for (ll i = 1; i < v.size(); i++) {

    if (v[i] != k) {
      k = v[i];
      ans += 1;
    }
  }
  cout << ans << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll, ll> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    pbds;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  vector<pair<string, ll>> v;
  ll n;
  cin >> n;
  while (n--) {
    string s;
    cin >> s;
    int ans = 0;
    for (ll i = 0; i < v.size(); i++) {
      if (v[i].fi == s) {
        v[i].se += 1;
        ans = 1;
      }
    }
    if (ans == 0) {
      v.pb(mp(s, 1));
    }
  }
  cout << v.size() << endl;
  return 0;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int countDistinct(string arr[], int n) {
  // First sort the array so that all
  // occurrences become consecutive
  sort(arr, arr + n);

  // Traverse the sorted array
  int res = 0;
  for (int i = 0; i < n; i++) {

    // Move the index ahead while
    // there are duplicates
    while (i < n - 1 && arr[i] == arr[i + 1])
      i++;

    res++;
  }

  return res;
}
int main() {
  int n;
  cin >> n;

  cin.ignore(numeric_limits<streamsize>::max(), '\\n');

  string a[n];

  for (int i = 0; i < n; i++) {
    getline(cin, a[i]);
  }

  cout << countDistinct(a, n);
}

Error: TLE

Fixed submission:

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

int countDistinct(string arr[], int n) {
  int res = 1;

  // Pick all elements one by one
  for (int i = 1; i < n; i++) {
    int j = 0;
    for (j = 0; j < i; j++)
      if (arr[i] == arr[j])
        break;

    // If not printed earlier, then print it
    if (i == j)
      res++;
  }
  return res;
}

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

  cin.ignore(numeric_limits<streamsize>::max(), '\\n');

  string a[n];

  for (int i = 0; i < n; i++) {
    getline(cin, a[i]);
  }

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

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  int counter = 1;
  cin >> n;
  string s[n];
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  sort(s, s + n);
  for (int i = 1; i < n; i++) {
    if (s[i - 1] != s[i]) {
      counter += 1;
    }
  }
  cout << counter << endl;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int n;
struct wu {
  char c[11];
} a[20005];
int main() {
  int i, j, k, b, d, e;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%s", &a[i].c);
  }
  for (i = 1; i <= n; i++) {
    for (j = 1; j < i; j++) {
      k = 1;
      b = strlen(a[i].c);
      d = strlen(a[j].c);
      if (b != d)
        n--;
      else {
        e = max(b, d);
        for (k = 1; k <= e; k++) {
          if (a[i].c[k] != a[j].c[k]) {
            k = 0;
            break;
          }
        }
        if (k == 0)
          n--;
      }
    }
  }
  printf("%d", n);
  return 0;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, n) for (long long i = 0; i < n; i++)
#define Rep(i, n) for (long long i = 1; i < n; i++)
#define ll long long
#include <cmath>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <vector>

using namespace std;
#define PI acos(-1)

int main() {
  int N;
  cin >> N;
  set<string> st;
  rep(i, N) {
    string s;
    cin >> s;
    st.insert(s);
  }
  cout << st.size() << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (long long i = 0; i < n; i++)
#define Rep(i, n) for (long long i = 1; i < n; i++)
#define ll long long
#include <cmath>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <vector>

using namespace std;
#define PI acos(-1)

int main() {
  ll N;
  cin >> N;
  vector<string> s;
  ll ans = 0;
  rep(i, N) {
    string S;
    cin >> S;
    bool ok = true;
    rep(j, s.size()) {
      if (S == s[j]) {
        ok = false;
        break;
      }
    }
    if (ok) {
      ans++;
      s.push_back(S);
    }
  }
  cout << ans << 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[i];
  }
  sort(S.begin(), S.end());
  S.erase(unique(S.begin(), S.end()), S.end());
  //  vector<string> prize;
  // for (int i = 0; i < N; i++) {
  // if (find(prize.begin(), prize.end(), S[i]) == prize.end()) {
  //   prize.push_back(S[i]);
  //}
  //}
  cout << S.size() << endl;

  return 0;
}


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[i];
  }
  vector<string> prize;
  for (int i = 0; i < N; i++) {
    if (find(prize.begin(), prize.end(), S[i]) == prize.end()) {
      prize.push_back(S[i]);
    }
  }
  cout << prize.size() << 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);
  }
  /*
  int count = N;
  for (int i = 0; i < N; i++)
  {
      for (int j = i + 1; j < N; j++)
      {
          if (i != j && S.at(i) == S.at(j))
          {
              count--;
              S.at(i) = "aaaaaaaaaaaaaahkrstomnjaibgdfnabdi";
              break;
          }
      }
  }
  cout << count << endl;
  */
  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);
  }
  int count = N;
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      if (i != j && S.at(i) == S.at(j)) {
        count--;
        S.at(i) = "aaaaaaaaaaaaaahkrstomnjaibgdfnabdi";
        break;
      }
    }
  }
  cout << count << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
  int n, ans = 1;
  cin >> n;
  vector<string> c;
  string str, ring;
  cin >> str;
  c.push_back(str);

  for (int i = 1; i < n; i++) {
    cin >> ring;
    c.push_back(ring);
  }

  sort(c.begin(), c.end());
  for (int i = 0; i < n - 1; i++) {
    if (c[i] != c[i + 1])
      ans++;
  }

  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
  int n, ans = 1;
  cin >> n;
  vector<string> c;
  string str, ring;
  cin >> str;
  c.push_back(str);

  for (int i = 1; i < n; i++) {
    cin >> ring;
    for (int j = 0; j < c.size(); j++) {
      if (c.at(j) == ring)
        break;
      if (j == c.size() - 1) {
        c.push_back(ring);
        ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  int n;
  cin >> n;
  string s[n], t;
  int count = 1;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  sort(s, s + n);
  t = s[0];
  for (int i = 1; i < n; i++) {
    if (s[i] != t) {
      t = s[i];
      count++;
    }
  }

  cout << count;

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int64_t n;
  cin >> n;
  string s[n], t;
  cin >> s[0];
  int64_t count = 1;
  for (int64_t i = 1; i < n; i++) {
    cin >> t;
    for (int64_t j = 0; j < count; j++) {
      if (s[j] == t) {
        break;
      } else if (j == count - 1) {
        s[count] = t;
        count++;
        break;
      }
    }
  }

  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;
  vector<string> A;
  for (int i = 0; i < N; i++) {
    string S;
    cin >> S;
    A.push_back(S);
  }
  sort(A.begin(), A.end());
  int ans = N;
  for (int i = 0; i < N - 1; i++) {
    if (A.at(i) == A.at(i + 1))
      ans--;
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include "bits/stdc++.h"
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<string> A;
  for (int i = 0; i < N; i++) {
    string S;
    cin >> S;
    if (A.empty())
      A.push_back(S);
    else {
      bool check = true;
      for (int j = 0; j < A.size(); j++) {
        if (A.at(j) == S)
          check = false;
      }
      if (check)
        A.push_back(S);
    }
  }
  cout << A.size() << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <set>
#define endl '\\n'

using namespace std;

int main() {
  set<string> s;

  int n = 0;
  cin >> n;

  string temp;

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

  cout << s.size();

  return 0;
}

Error: TLE

Fixed submission:

#include <cstring>
#include <iostream>
using namespace std;
char c[1000000][11];
int main() {
  int n;
  int flag = 0;
  int ct = 0;
  // cout<<"d"<<endl;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> c[i];
    flag = 0;
    // cout<<c[i]<<endl;
    for (int j = 0; j < i; j++) {
      if (strcmp(c[i], c[j]) == 0) {
        flag = 1;
        break;
      }
    }
    if (flag)
      continue;
    ct++;
  }
  cout << ct << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#include <stdio.h>
using namespace std;
int main() {
  int i, n, t = 0, j;
  cin >> n;
  string s[n];
  for (i = 0; i < n; i++) {

    cin >> s[i];
  }
  sort(s, s + i);
  for (i = 0; i < n; i++) {
    if (s[i] == s[i - 1])
      t++;
  }
  cout << n - t << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <stdio.h>
using namespace std;
int main() {
  int i, n, t = 0, j;
  cin >> n;
  string s[n];
  for (i = 0; i < n; i++) {

    cin >> s[i];
    /*for(j=0;j<i;j++)
    {
        if(s[i]==s[j])
           {
               t++;
            break;}
    }*/
  }
  for (i = 0; i < n; i++) {
    for (j = i + 1; j < n; j++) {
      if (s[i] == s[j]) {
        t++;
        break;
      }
    }
  }
  cout << n - t << 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;
  string s;
  map<string, int> history;
  while (cin >> s) {
    history[s]++;
  }
  cout << history.size() << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  int n;
  cin >> n;
  vector<string> history;
  string s;
  while (cin >> s) {
    if (find(history.begin(), history.end(), s) == history.end()) {
      history.push_back(s);
    } else {
      ;
    }
  }
  cout << history.size() << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

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

Error: TLE

Fixed submission:

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

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

bool comparator(string a, string b) { return a < b; }
int main() {
  int n;
  cin >> n;
  string arr[n];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  sort(arr, arr + n, comparator);
  int p = 1;
  for (int i = 1; i < n; i++) {
    if (arr[i] != arr[i - 1]) {
      p++;
    }
  }
  cout << p << endl;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#define ll long long int
#define MOD 1000000007
using namespace std;

int main() {
  int n;
  cin >> n;
  string str[n];
  int p = 0, q = 0;
  for (int i = 0; i < n; i++) {
    cin >> str[i];
    for (int j = i - 1; j >= 0; j--) {
      if (str[j] == str[i]) {
        p = 1;
        break;
      }
    }
    if (p == 0) {
      q++;
    }
    p = 0;
  }
  cout << q << endl;

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

#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <map> //map<int, int> x;
#include <numeric>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i <= (int)(n); i++)
#define SIZE_OF_ARRAY(array) (sizeof(array) / sizeof(array[0]))

using ll = long long;
using namespace std;
int main() {
  int n;
  int count = 0;
  cin >> n;
  string a;
  vector<string> strlist(10000000);
  rep(i, n) cin >> strlist[i];

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

  cout << int(strlist.size() - 1) << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <map> //map<int, int> x;
#include <numeric>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i <= (int)(n); i++)
#define SIZE_OF_ARRAY(array) (sizeof(array) / sizeof(array[0]))

using ll = long long;
using namespace std;
int main() {
  int n;
  int count = 0;
  cin >> n;
  string a;
  vector<string> strlist(1000);
  rep(i, n) cin >> strlist[i];

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

  cout << int(strlist.size() - 1) << endl;
  return 0;
}
Problem p02701 (C++) — buggy submission, verdict: Runtime Error

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

  int N;
  cin >> N;
  std::set<std::string> str;
  string str1;
  for (int i = 0; i < N; i++) {
    cin >> str1;
    str.insert(str1);
  }
  cout << str.size();
}

Error: -11

Fixed submission:


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

int main() {
  int n, count = 0;
  cin >> n;
  vector<string> v;
  for (int i = 0; i < n; i++) {
    v.push_back(v[i]);
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; i < n; j++) {
      if (v[i] != v[j])
        count++;
    }
  }
  cout << count;

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

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

void Main() {
  int n;
  cin >> n;
  vector<string> s(n);
  REP(i, n)
  cin >> s[i];

  int l;

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

  l = s.size();
  printf("%d", l);
}

int main() {
  std::cout << std::fixed << std::setprecision(15);
  Main();
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

void Main() {
  int n;
  int flg = 0;
  cin >> n;
  string hikaku;
  vector<string> s(n);
  vector<string> s2(n);
  int count = n;
  REP(i, n)
  cin >> s[i];

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

  printf("%d", count);
}

int main() {
  std::cout << std::fixed << std::setprecision(15);
  Main();
}
Problem p02701 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <map>
using namespace std;
map<string, bool> strs;
string str;
int main() {
  cin >> str;
  while (cin >> str) {
    strs[str] = 1;
  }
  cout << strs.size() << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
bool cmp(const string m, const string n) { return m > n; }
int n, t;
string str[100005];
int main() {
  ios::sync_with_stdio(0);
  cin >> n;
  for (; t < n; t++) {
    cin >> str[t];
  }
  if (!is_sorted(str, str + n, cmp))
    sort(str, str + n, cmp);
  cout << unique(str, str + n) - str << endl;
  return 0;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

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

  long long count = 1;
  for (long long i = 0; i < N - 1; i++) {
    if (S.at(i) != S.at(i + 1)) {
      count++;
    }
  }

  cout << count;
}

Error: TLE

Fixed submission:

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

int main() {
  long long N;
  cin >> N;
  vector<string> S(1);
  cin >> S.at(0);
  for (long long i = 1; i < N; i++) {
    string gacha;
    cin >> gacha;
    for (long long j = 0; j <= S.size() - 1; j++) {
      if (S.at(j) == gacha) {
        break;
      } else if (j == S.size() - 1) {
        S.push_back(gacha);
      }
    }
  }
  cout << S.size();
}
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 t;
    cin >> t;
    s.insert(t);
  }
  cout << s.size();
}


Error: TLE

Fixed submission:

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

  int n;
  string s[220000] = {};
  cin >> n;
  for (int i = 0; i < n; i++) {
    bool flag = true;
    string t;
    cin >> t;
    for (int j = 0; j < n; j++) {
      if (t == s[j])
        flag = false;
    }
    if (flag)
      s[i] = t;
  }
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (0 < s[i].size())
      cnt++;
  }
  cout << cnt;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main(int argc, const char **argv) {
  int tried = 0;
  std::cin >> tried;

  std::map<std::string, long long> result;
  for (int loop = 0; loop < tried; loop++) {
    std::string item{0};
    std::cin >> item;
    result[item]++;
  }

  std::cout << result.size() << std::endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <deque>
#include <iostream>
#include <string>

int main(int argc, const char **argv) {
  int tried = 0;
  std::cin >> tried;

  std::deque<std::string> types;
  for (int loop = 0; loop < tried; loop++) {
    std::string item{0};
    std::cin >> item;
    auto itr = std::find(types.begin(), types.end(), item);
    if (itr == types.end())
      types.push_front(item); //	No hit
  }

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

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

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

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

  unordered_map<string, int> map;
  for (int i = 0; i < N; i++) {
    map[S[i]] = 1;
  }

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

Error: 0

Fixed submission:

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

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

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

  unordered_map<string, int> map;
  for (int i = 0; i < N; i++) {
    map[S[i]] = 1;
  }

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