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

#include <iostream>
#include <set>
#include <string>
#include <vector>

using namespace std;

// int main_old()
// {
// int N;

// cin >> N;

// vector<string> S(N);

// cin >>S[0];

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

//     string k;

//     cin >>k;

//     int count =0;

//     for(int j =0;j<S.size();j++){

//         if (S[j] == k){

//             count =1;
//             break;

//         }

//     }

//     if(count ==0){

//         S.push_back(k);

//     }

// }

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

// return 0;

// }

int main() {
  int N;

  cin >> N;

  set<string> S;

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

    string k;

    cin >> k;

    int count = 0;

    S.insert(k);
  }

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

  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
  int N;

  cin >> N;

  vector<string> S(1);

  cin >> S[0];

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

    string k;

    cin >> k;

    int count = 0;

    for (int j = 0; j < S.size(); j++) {

      if (S[j] == k) {

        count = 1;
        break;
      }
    }

    if (count == 0) {

      S.push_back(k);
    }
  }

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

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

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

using namespace std;

int main(void) {
  int num;
  char s[10];
  vector<string> vec;

  if (scanf("%d", &num)) {
    for (int i = 0; i < num; ++i) {
      if (scanf("%s", s)) {
      }
      vec.push_back(s);
    }
  }

  sort(vec.begin(), vec.end());
  vec.erase(std::unique(vec.begin(), vec.end()), vec.end());

  num = vec.size();
  printf("%d", num);

  return 0;
}

Error: TLE

Fixed submission:

#include <cstring>
#include <stdio.h>
#include <string>

using namespace std;

int main(void) {
  int num;
  char s[10];
  string ans[10][200000];
  int cnt[10];
  bool b = true;
  int len = 0;
  int i, j, k;

  if (scanf("%d", &num)) {
    for (i = 0; i < num; ++i) {
      if (scanf("%s", s)) {
      }
      b = true;
      len = strlen(s) - 1;
      k = cnt[len] - 1;

      for (j = 0; j <= k; ++j) {
        if (ans[len][j] == s) {
          b = false;
          break;
        }
        if (k >= 0 && ans[len][k] == s) {
          b = false;
          break;
        }
        k--;
      }
      if (b) {
        ans[len][cnt[len]] = s;
        cnt[len]++;
      }
    }
  }
  num = 0;
  for (i = 0; i < 10; ++i) {
    num += cnt[i];
  }

  printf("%d", num);

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

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

int main() {
  long long n, sum = 0, mod = 2019;
  string a;
  cin >> n;
  vector<string> st(n);
  rep(i, n) { cin >> st[i]; }
  sort(st.begin(), st.end());
  for (int i = 0; i < n - 1; i++) {
    if (st[i] == st[i + 1])
      sum++;
  }

  cout << n - sum << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  long long n, sum = 0, mod = 2019;
  string a;
  cin >> n;
  vector<string> st(1);
  cin >> st[0];

  for (int i = 0; i < n - 1; i++) {
    sum = 0;
    cin >> a;
    for (int j = 0; j < st.size(); j++) {
      if (a == st[j]) {
        sum = 1;
        break;
      }
    }
    if (sum == 0)
      st.push_back(a);
  }
  cout << st.size() << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <set>
#include <string>
#include <vector>

using namespace std;

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

Error: TLE

Fixed submission:

#include <iostream>
#include <set>
#include <string>
#include <vector>

using namespace std;

int main() {
  set<string> num;
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) {
    vector<string> str(N);
    cin >> str.at(i);
    num.insert(str.at(i));
  }
  cout << num.size() << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int n;
  int count = 0;
  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());
  cout << s.size();
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;

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

  for (int i = 0; i < n; i++) {
    if (b[i] != false) {
      count++;
      string check = s[i];
      for (int j = i + 1; j < n; j++) {
        if (check == s[j])
          b[j] = false;
      }
    }
  }
  cout << count;
  return 0;
}
Problem p02701 (C++) — buggy submission, verdict: Runtime Error

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

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

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

Error: -11

Fixed submission:

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

int main() {
  int n;
  cin >> n;
  int counter = 0;
  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; i++) {
    if (s[i] == s[i + 1]) {
      s.erase(s.begin() + i - 1);
    }
  }
  cout << s.size() << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define FASTIO                                                                 \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define ll long long int
#define ld long double
#define vll vector<ll>
#define pll pair<ll, ll>
#define vl(p) vector<p>
#define w while
#define For(i, s, x) for (i = s; i < x; i++)
#define Fore(i, s, x) for (i = s; i <= x; i++)
#define FOR(i, x) for (i = 0; i < x; i++)
#define Rof(i, s, x) for (i = s; i >= x; i--)
#define all(v) v.begin(), v.end()
#define it(r, v) for (auto r = v.begin(); r != v.end(); r++)
#define pb push_back
#define in insert
#define sz size()
#define F first
#define S second
#define nl cout << "\\n"
#define pr(a) cout << a << " "
#define pr2(a, b) cout << a << " " << b << "\\n"
#define pr3(a, b, c) cout << a << " " << b << " " << c << "\\n"
#define mod 1000000007
int main() {
  FASTIO;
  ll n, i, j, count = 0;
  cin >> n;
  std::map<string, ll> Map;
  string s;
  for (i = 0; i < n; i++) {
    cin >> s;
    Map[s] = i;
  }

  cout << Map.size() << "\\n";
}


Error: TLE

Fixed submission:

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

#define FASTIO                                                                 \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define ll long long int
#define ld long double
#define vll vector<ll>
#define pll pair<ll, ll>
#define vl(p) vector<p>
#define w while
#define For(i, s, x) for (i = s; i < x; i++)
#define Fore(i, s, x) for (i = s; i <= x; i++)
#define FOR(i, x) for (i = 0; i < x; i++)
#define Rof(i, s, x) for (i = s; i >= x; i--)
#define all(v) v.begin(), v.end()
#define it(r, v) for (auto r = v.begin(); r != v.end(); r++)
#define pb push_back
#define in insert
#define sz size()
#define F first
#define S second
#define nl cout << "\\n"
#define pr(a) cout << a << " "
#define pr2(a, b) cout << a << " " << b << "\\n"
#define pr3(a, b, c) cout << a << " " << b << " " << c << "\\n"
#define mod 1000000007
int main() {
  FASTIO;
  ll n, i, j, count = 0;
  cin >> n;
  std::map<ll, string> Map;
  string s;
  for (i = 0; i < n; i++) {
    cin >> s;
    Map[i] = s;
  }
  for (i = 0; i < n; i++) {
    for (j = i + 1; j < n; j++)

      if (Map[i] == Map[j] && Map[j] != "0") {
        Map[j] = "0";
      }
  }
  for (i = 0; i < n; i++) {
    if (Map[i] != "0")
      count++;
  }
  cout << count << "\\n";
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <set>
#include <string>
#include <vector>

using namespace std;

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

int main(void) {
  int ans = 0;
  int N;
  cin >> N;

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

  set<string> strList;

  ans++;
  strList.insert(S[0]);

  rep(i, N) {
    if (strList.find(S[i]) != strList.end()) {
      continue;
    }

    ans++;
    strList.insert(S[i]);
    //                cout << " add:" << strList[listcnt + 1] << endl;
  }

  cout << ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>
#include <vector>

using namespace std;

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

int main(void) {
  int ans = 0;
  int N;
  cin >> N;

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

  vector<string> strList;

  ans++;
  strList.push_back(S[0]);

  rep(i, N) {
    bool isdiff = false;
    int size = strList.size();

    for (int listcnt = 0; listcnt < size; listcnt++) {
      //            cout << strList[listcnt];
      if (S[i] == strList[listcnt]) {
        isdiff = false;
        break; // 同じ場合は既にあるので無視し次の入力を見る
      } else {
        isdiff = true;
      }
    }

    if (isdiff == true) {
      ans++;
      strList.push_back(S[i]);
      //                cout << " add:" << strList[listcnt + 1] << endl;
    }
  }

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


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<string> vec(n);
  for (int i = 0; i < n; i++) {
    cin >> vec[i];
  }
  int cnt = 1;
  int j = 0;
  for (int i = 1; i < n; i++) {
    for (j = 0; j < i; j++)
      if (vec[i] == vec[j])
        break;
    if (i == j)
      cnt++;
  }
  cout << cnt << 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 < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using Graph = vector<vector<int>>;
using ll = long long;

int main() {
  ll n;
  cin >> n;
  vector<string> s(n);
  int count = 1;
  rep(i, n) { cin >> s[i]; }
  sort(s.begin(), s.end());
  s.push_back(s.back());
  rep(i, n) {
    if (s[i] != s[i + 1]) {
      count++;
    }
  }
  cout << count << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  ll n;
  cin >> n;
  vector<string> s(1, " ");
  rep(i, n) {
    string is;
    cin >> is;
    s.push_back(is);
    rep(j, s.size() - 1) {
      if (s[j] == s.back()) {
        s.pop_back();
        break;
      }
    }
  }
  cout << s.size() - 1 << 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> data(N);
  for (int i = 0; i < N; i++) {
    cin >> data.at(i);
  }
  sort(data.begin(), data.end());
  int count = N;
  for (int i = 0; i < N - 1; i++) {
    if (data.at(i) == data.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> data(N);
  for (int i = 0; i < N; i++) {
    cin >> data.at(i);
  }
  int count = N;
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      if (data.at(i) == data.at(j)) {
        count--;
        break;
      }
    }
  }
  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> s1;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    s1.insert(s);
  }
  cout << s1.size() << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n;
  cin >> n;
  vector<string> v;
  for (long long int i = 0; i < n; i++) {
    string s;
    cin >> s;
    v.push_back(s);
  }
  vector<long long int> v1;
  for (long long int i = 0; i < n; i++) {
    long long int count = 1;
    for (long long int j = 0; j < n; j++) {
      if (v[i] != v[j]) {
        count++;
      }
    }
    v1.push_back(count);
  }
  long long int sum = 0;
  int m = v1.size();
  for (long long int i = 0; i < v1.size(); i++) {
    sum = sum + v1[i];
  }
  long long int ans = (sum / m);
  cout << ans << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#include <map>
#include <string>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  for (int i = 0; i < n; i++)
    cin >> s[i];
  int sum = 0;
  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[i];
  int sum = 0;
  for (int i = 0; i < n; i++) {
    sum++;
    for (int k = 0; k < i; k++) {
      if (s[i] == s[k]) {
        sum--;
        break;
      }
    }
  }
  cout << sum << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
#define mp make_pair
#define INF 1e9

void init() {
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
}
int main() {
  init();
  int N, ans = 0;
  cin >> N;
  vector<string> str(N);
  vector<vector<vector<string>>> data(11, vector<vector<string>>(128));
  rep(i, N) {
    cin >> str[i];
    int flag = 1;
    rep(j, data[str[i].size()][int(str[i][0])].size()) {
      rep(k, str[i].size()) {
        if (data[str[i].size()][int(str[i][0])][j][k] != str[i][k]) {
          break;
        }
        if (k == (str[i].size() - 1)) {
          flag = 0;
          break;
        }
      }
      if (flag == 0)
        break;
    }
    if (flag == 1) {
      data[str[i].size()][int(str[i][0])].push_back(str[i]);
      ans++;
    }
  }
  cout << ans << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
#define mp make_pair
#define INF 1e9

void init() {
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
}
int main() {
  init();
  int N, ans = 0;
  cin >> N;
  vector<string> str(N);
  vector<vector<vector<string>>> data(11, vector<vector<string>>(128));
  rep(i, N) {
    cin >> str[i];
    int flag = 1;
    rep(j, data[str[i].size()][int(str[i][0])].size()) {
      if (str[i] == data[str[i].size()][int(str[i][0])][j]) {
        flag = 0;
        break;
      }
    }
    if (flag == 1) {
      data[str[i].size()][int(str[i][0])].push_back(str[i]);
      ans++;
    }
  }
  cout << ans << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
set<string> s;
string t;
long long n;

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

  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
string a[100005];
long long n, k;

int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  for (int i = 0; i <= n; i++) {
    if (a[i] != a[i + 1])
      k++;
  }
  cout << k;
  return 0;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int N;
  int count = 1;
  string tmp;
  cin >> N;
  vector<string> list(N); // 景品リスト

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

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

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

  cout << count;
}

Error: TLE

Fixed submission:

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

int main() {
  int N;
  int count = 0;
  string tmp;
  cin >> N;
  vector<string> list(N); // 景品リスト

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

    for (int j = 0; j <= count; j++) {
      if (list[j] == tmp)
        break;

      if (j == count) {
        list[j] = tmp;
        count++;
        break;
      }
    }
  }

  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++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define ALL(n) begin(n), end(n)
using namespace std;
using ll = long long;

int main() {
  int n;
  cin >> n;
  vector<string> name(n);
  rep(i, n) cin >> name[i];

  sort(ALL(name));
  name.erase(unique(name.begin(), name.end()), name.end());

  cout << name.size() << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define ALL(n) begin(n), end(n)
using namespace std;
using ll = long long;

int main() {
  int n;
  cin >> n;
  vector<string> name(n);
  rep(i, n) cin >> name[i];

  int cnt = 0;

  while (name.size() != 0) {
    int i = name.size() - 1;
    cnt++;
    for (int j = i - 1; j >= 0; j--) {
      if (name[name.size() - 1] == name[j]) {
        name.erase(name.begin() + j);
      }
    }
    name.erase(name.end());
  }

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

#include <bits/stdc++.h>
using namespace std;
// Setを使って、新たな要素は追加していき、最後にサイズをチェックする
int main() {
  int N;
  scanf("%d", &N);
  string inString;

  set<string> set_dict;
  int a = 0;
  while (a < N) {
    cin >> inString;
    set_dict.insert(inString);

    a++;
  }
  cout << set_dict.size() << endl;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int N;
  scanf("%d", &N);
  string inString;
  vector<string> v;
  int num_dict = 0;
  int result = 0;
  int a = 0;
  while (a < N) {
    cin >> inString;
    if (find(v.begin(), v.end(), inString) == v.end()) {
      v.push_back(inString);
      num_dict += 1;
    }
    a++;
  }
  printf("%d\\n", num_dict);
}
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 x;
    cin >> x;
    S.insert(x);
  }
  cout << S.size() << endl;
}

Error: TLE

Fixed submission:

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

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

int main() {
  int N, cnt = 0;
  cin >> N;
  vector<string> S;
  string str;
  rep(i, N) {
    cin >> str;
    S.insert(S.end(), 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 <algorithm>
#include <iostream>
#include <iterator>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main() {
  int N, cnt = 0;
  cin >> N;
  vector<string> S;
  string str;
  rep(i, N) {
    cin >> str;
    if (i == 0) {
      S.insert(S.end(), str);
      cnt++;
    } else {
      vector<string>::iterator result = find(S.begin(), S.end(), str);
      if (result == S.end()) {
        S.insert(S.end(), str);
        cnt++;
      }
    }
  }
  cout << cnt << endl;
  return 0;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
#ifndef ONLINE_JUDGE
  // for getting input from input.txt
  freopen("input.txt", "r", stdin);
  // for writing output to output.txt
  freopen("output.txt", "w", stdout);
#endif

  int n, uniq = 0;
  cin >> n;
  bool dupe;
  string vars[n];
  for (int i = 0; i < n; i++) {
    cin >> vars[i];
  }
  unordered_set<string> s(vars, vars + n);
  cout << s.size();
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
#ifndef ONLINE_JUDGE
  // for getting input from input.txt
  freopen("input.txt", "r", stdin);
  // for writing output to output.txt
  freopen("output.txt", "w", stdout);
#endif

  int n, uniq = 0;
  cin >> n;
  bool dupe;
  string vars[n];
  for (int i = 0; i < n; i++) {
    cin >> vars[i];
  }
  for (int j = 0; j < n; j++) {
    dupe = false;
    for (int k = 0; k < j; k++) {
      if ((k != j) && (vars[j] == vars[k])) {
        dupe = true;
        break;
      }
    }
    if (!dupe)
      uniq++;
  }
  cout << uniq;
  return 0;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#pragma GCC optimize("Ofast")
#include <algorithm>
#include <bits/stdc++.h>
#include <cstring>
#include <iostream>
#include <math.h>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
  ll N, n = 0;
  int i;
  string same;

  cin >> N;

  vector<string> S(N);
  set<string> ans;

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

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

Error: TLE

Fixed submission:

#pragma GCC optimize("Ofast")
#include <algorithm>
#include <bits/stdc++.h>
#include <cstring>
#include <iostream>
#include <math.h>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
  ll N, n = 0;
  int i;
  string same;

  cin >> N;

  vector<string> S(N);

  for (i = 0; i < N; i++) {
    cin >> S[i];
    if (i > 0) {
      if (*lower_bound(S.begin(), S.begin() + i - 1, S[i]) == S[i]) {
        n++;
      }
    }
  }

  sort(S.begin(), S.end());
  for (i = 0; i < N; i++) {
    same = S[i];
    i++;
    while (same == S[i]) {
      n++;
    }
    i--;
  }

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

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

int main() {
  int N = 0;
  std::cin >> N;

  std::map<std::string, int> map_get;

  for (int i = 0; i < N; i++) {
    std::string str;
    std::cin >> str;

    if (map_get.count(str) == false) {
      map_get[str] = 1;
    }
  }

  std::cout << map_get.size() << std::endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>
#include <vector>

int main() {
  int64_t N = 0;
  std::cin >> N;

  std::vector<std::string> vec_get(0);

  for (int64_t i = 0; i < N; i++) {
    std::string str;
    std::cin >> str;
    bool flag = false;
    for (int64_t j = 0; j < vec_get.size(); j++) {
      if (str == vec_get.at(j)) {
        flag = true;
      }
    }
    if (flag == false) {
      vec_get.push_back(str);
    }
  }

  std::cout << vec_get.size() << std::endl;

  return 0;
}