alexjercan/bugnet huggingface dataset:
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;
  string cnt;
  for (int i = 0; i < n; i++) {
    cin >> cnt;
    s.push_back(cnt);
  }
  sort(s.begin(), s.end());
  int kind = 0;
  for (int k = 0; k < n - 1; k++) {
    if (s[k] != s[k + 1]) {
      kind++;
    }
  }
  cout << kind + 1;
}

Error: TLE

Fixed submission:

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

int main() {
  int N, i;
  cin >> N;
  vector<string> v;
  int counter = 0;
  for (i = 0; i < N; i++) {
    string s;
    cin >> s;
    int flag = 0;
    int j;
    if (v.size() > 0) {
      for (j = 0; j < v.size(); j++) {
        // cout<<s<<endl;
        // cout<<v[j]<<endl;
        // cout<<s.compare(v[j])<<endl;
        if (s.compare(v[j]) == 0) {
          flag = 1;
          break;
        }
      }
      if (flag == 0) {
        v.push_back(s);
        counter++;
      }
    } else {
      v.push_back(s);
      counter++;
      // cout<<counter;
    }
  }
  cout << counter << endl;

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

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef vector<int> vec1;
typedef vector<string> vec2;
typedef vector<double> vec3;

int main() {

  int n;
  cin >> n;
  vec2 s(n);
  for (int i = 0; i < n; i++)
    cin >> s.at(i);
  sort(s.begin(), s.end());

  int ans = 1;
  for (int i = 1; i < n; i++) {
    if (s.at(i - 1) != s.at(i)) {
      ans++;
    }
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef vector<int> vec1;
typedef vector<string> vec2;
typedef vector<double> vec3;

int main() {

  int n;
  cin >> n;
  vec2 s(n);
  for (int i = 0; i < n; i++)
    cin >> s.at(i);

  vec2 tmp(0);
  tmp.push_back(s.at(0));
  int ans = 1;
  int c = 0;
  for (int i = 1; i < n; i++) {
    c = 0;
    for (int j = 0; j < tmp.size(); j++) {
      if (s.at(i) == tmp.at(j)) {
        c++;
        break;
      }
    }
    if (c == 0) {
      tmp.push_back(s.at(i));
      ans++;
    }
  }
  cout << ans << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
string s[N];
set<string> st;
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    st.insert(s[i]);
  }
  cout << st.size() << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
string s[N];
set<string> st;
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    st.insert(s[i]);
  }
  cout << st.size() << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Runtime Error

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

using namespace std;

long n;
map<string, long> mp;
string str;

int main() {

  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> str;
    mp[str] += mp[str] + 1;
  }

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

  return 0;
}


Error: 0

Fixed submission:

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

using namespace std;

int main() {

  long n;
  string s[20010];

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

  map<string, long> map;

  for (int i = 0; i < n; i++)
    map[s[i]] += map[s[i]] + 1;

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

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

#include <algorithm>
#include <iostream>
#include <set>
#include <string>

using namespace std;

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

Error: TLE

Fixed submission:

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

using namespace std;

int main() {
  int N;
  cin >> N;
  vector<string> kujibiki(N);
  for (int i = 0; i < N; i++) {
    cin >> kujibiki.at(i);
  }
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      if (kujibiki.at(i) == kujibiki.at(j)) {
        kujibiki.at(j) = "0";
      }
    }
  }
  kujibiki.erase(remove(kujibiki.begin(), kujibiki.end(), "0"), kujibiki.end());
  cout << kujibiki.size() << endl;
}
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++)
#define ll long long
#define BIT_FLAG_0 (1 << 0) // 0000 0000 0000 0001
#define BIT_FLAG_1 (1 << 1) // 0000 0000 0000 0010
#define BIT_FLAG_2 (1 << 2) // 0000 0000 0000 0100
#define BIT_FLAG_3 (1 << 3) // 0000 0000 0000 1000
#define BIT_FLAG_4 (1 << 4) // 0000 0000 0001 0000
#define BIT_FLAG_5 (1 << 5) // 0000 0000 0010 0000
#define BIT_FLAG_6 (1 << 6) // 0000 0000 0100 0000
#define BIT_FLAG_7 (1 << 7) // 0000 0000 1000 0000

int main() {
  ll n;
  cin >> n;
  set<string> s;
  string str;
  rep(i, n) {
    cin >> str;
    s.insert(str);
  }
  cout << s.size() << endl;
}
/*
    vector<string> s(n);
    rep(i,n){
        cin >> s[i];
    }
    sort(s.begin(),s.end());
    rep(i,n){
        if(s[i]==s[i+1]){
                s.erase(s.begin()+i);
                i--;
            }
        }
    cout << s.size() << endl;
    }
*/


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define BIT_FLAG_0 (1 << 0) // 0000 0000 0000 0001
#define BIT_FLAG_1 (1 << 1) // 0000 0000 0000 0010
#define BIT_FLAG_2 (1 << 2) // 0000 0000 0000 0100
#define BIT_FLAG_3 (1 << 3) // 0000 0000 0000 1000
#define BIT_FLAG_4 (1 << 4) // 0000 0000 0001 0000
#define BIT_FLAG_5 (1 << 5) // 0000 0000 0010 0000
#define BIT_FLAG_6 (1 << 6) // 0000 0000 0100 0000
#define BIT_FLAG_7 (1 << 7) // 0000 0000 1000 0000

int main() {
  ll n;
  cin >> n;
  vector<string> s(n);
  rep(i, n) { cin >> s[i]; }
  sort(s.begin(), s.end());
  rep(i, n) {
    if (s[i] == s[i + 1]) {
      s.erase(s.begin() + i);
      i--;
    }
  }
  cout << s.size() << endl;
}
/*rep(i,n){
    cout << s[i] << endl;
}*/
Problem p02701 (C++) — buggy submission, verdict: Runtime Error

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

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

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

  vector<string> s(n);
  rep(i, n) cin >> s[i];

  int cnt = 1;
  sort(s.begin(), s.end());
  rep(i, n - 1) if (s[i] != s[i + 1]) cnt++;
  cout << cnt;
}

Error: -11

Fixed submission:

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

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

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

  vector<string> s;
  rep(i, n) cin >> s[i];

  int cnt = 1;
  sort(s.begin(), s.end());
  rep(i, n - 1) {
    if (s[i] != s[i + 1])
      cnt++;
  }
  cout << cnt;
}
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 int;
using vec = vector<int>;
using P = pair<int, int>;

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

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

  sort(s.begin(), s.end());
  cout << (unique(s.begin(), s.end()) - s.begin()) << endl;
}


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 int;
using vec = vector<int>;
using P = pair<int, int>;

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

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

    bool f = true;
    rep(j, i) {
      if (s[j] == s[i]) {
        f = false;
      }
    }

    if (f) {
      c++;
    }
  }

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

#include <bits/stdc++.h>
using namespace std;
int main() {
  // write code  here
  int N;
  cin >> N;
  vector<string> S(N);
  //    string S;
  vector<string> _S;
  for (int i = 0; i < N; ++i) {
    cin >> S.at(i);
  }
  sort(S.begin(), S.end());

  _S.push_back(S.at(0));

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

  cout << num << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  // write code  here
  int N;
  cin >> N;
  //    vector<string>S(N);
  string S;
  vector<string> _S;
  for (int i = 0; i < N; ++i) {
    cin >> S;
    if (i == 0)
      _S.emplace_back(S);
    else {
      bool a = true;
      for (int j = 0; j < _S.size() / 2; ++j) {
        if (S == _S.at(j) || S == _S.at(_S.size() - j)) {
          a = false;
          break;
        }
      }
      if (a)
        _S.push_back(S);
    }
  }

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

  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> v;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    v.push_back(s);
  }
  sort(v.begin(), v.end());

  long long int cnt = 1;
  for (int i = 1; i < n; i++) {
    if (v[i - 1] != v[i]) {
      cnt++;
    }
  }
  cout << cnt << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  int n;
  cin >> n;
  vector<string> v;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    int j = 0;
    if (v.size() > 0) {
      for (j = 0; j < v.size(); j++) {
        if (s == v[j])
          break;
      }
    }
    if (j == v.size())
      v.push_back(s);
  }
  cout << v.size() << 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> vec(n);
  for (int i = 0; i < n; i++) {
    cin >> vec.at(i);
  }
  map<string, int> mp;

  for (int i = 0; i < vec.size(); i++) {
    mp[vec.at(i)] = 1;
  }

  cout << mp.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.at(i);
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i == j) {
        continue;
      }
      if (vec.at(i) == vec.at(j)) {
        vec.at(j) = "no";
      }
    }
  }
  int c = 0;
  for (int i = 0; i < n; i++) {
    if (vec.at(i) == "no") {
      c++;
    }
  }

  int result = n - c;

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

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

int main() {
  int n, count = 1;
  string hozon;

  cin >> n;
  vector<string> s(n);
  for (int i = 0; i < n; i++) {
    cin >> s.at(i);
  }
  sort(s.begin(), s.end());
  hozon = s.at(0);
  for (int j = 1; j < n; j++) {
    if (hozon != s.at(j)) {
      hozon = s.at(j);
      count++;
    }
  }
  cout << count;
}


Error: TLE

Fixed submission:

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

int main() {
  int n, count = 0;

  cin >> n;
  vector<string> s(n);
  for (int i = 0; i < n; i++) {
    int a = i;
    bool tasu = true;
    cin >> s.at(i);
    for (int j = 0; j < i; j++) {
      if (a < 1) {
        break;
      }
      if (s.at(i) == s.at(a - 1)) {
        tasu = false;
        break;
      }

      a--;
    }
    if (tasu == true) {
      count++;
    }
  }
  cout << count;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int n;
string s;
set<string> NoDup_s;

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

int main() {
  cin >> n;
  solve();
  cout << NoDup_s.size() << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  int n, c = 0, count = 1;
  string s[2 * 100000];
  string s2[2 * 100000];
  string tmp;

  cin >> n;

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

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

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

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

#include <bits/stdc++.h>
#include <iostream>
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: -6
terminate called after throwing an instance of 'std::length_error'
  what():  cannot create std::vector larger than max_size()


Fixed submission:

#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main() {
  int N;
  vector<string> S(N);
  cin >> 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() - 1 << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main(void) {
  int n;
  string s;
  map<string, int> mp;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s;
    mp[s];
  }
  cout << mp.size();
}

Error: TLE

Fixed submission:

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

int main(void) {
  int n;
  int count = 1;
  int flag = 0;
  string v[200000];
  string s;
  cin >> n >> s;
  v[0] = s;
  for (int i = 1; i < n; i++) {
    cin >> s;
    for (int j = 0; j < count; j++) {
      if (s == v[j]) {
        flag = 1;
        break;
      }
    }
    if (flag == 0) {
      v[count] = s;
      count++;
    }
    flag = 0;
  }
  cout << count;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <queue>

using namespace std;
typedef long long ll;

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

int main() {

  ll N;
  cin >> N;
  ll out = N;
  string S[N];
  rep(i, N) cin >> S[i];
  sort(S, S + N);
  rep(i, N) {
    if (S[i] == S[i + 1])
      out--;
  }
  cout << out << endl;
  return 0;
}


Error: TLE

Fixed submission:

#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <queue>

using namespace std;
typedef long long ll;

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

int main() {

  ll N;
  cin >> N;
  ll out = N;
  string S[N];
  rep(i, N) {
    cin >> S[i];
    rep(j, i) {
      if (S[i] == S[j]) {
        out--;
        break;
      }
    }
  }
  cout << out << endl;
  return 0;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <math.h>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
int main() {
  ll n;
  cin >> n;
  vector<string> s(n);
  rep(i, n) cin >> s[i];
  sort(s.begin(), s.end());
  ll cnt = 1;
  rep(i, n - 1) {
    if (s[i] != s[i + 1]) {
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <math.h>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
int main() {
  ll n;
  cin >> n;
  vector<string> s(n);
  vector<string> c(n);
  rep(i, n) {
    cin >> s[i];
    c[i] = s[i];
  }
  ll cnt = 0;
  for (ll i = 0; i < n; i++) {
    ll now = 0;
    for (ll j = 0; j < i; j++) {
      if (s[i] != c[j]) {
        now++;
      }
      if (now == i) {
        cnt++;
      }
    }
  }
  cout << cnt + 1 << endl;
  return 0;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

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

typedef long long ll;
typedef int64_t i6;

#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep2(i, n) for (ll i = 1; i <= n; ++i)
#define ALL(v) (v).begin(), (v).end()
#define Sort(x) sort(ALL(x))
#define Sort_rev(x)                                                            \\
  Sort(x);                                                                     \\
  reverse(ALL(x))

template <typename V, typename T> T find_num(V v, T num) {
  if (find(ALL(v), num) == v.end()) {
    return false;
  } else {
    return true;
  }
}

// π M_PI
// deg = rad*180/M_PI

int main() {
  ll n;
  cin >> n;
  string s[n];
  std::vector<string> v;
  // ll ans = n;
  rep(i, n) {
    cin >> s[i];
    v.push_back(s[i]);
    /*
    rep(j, i) {
        if ( s[i] == s[j] ) {
            ans--;
            break;
        }
    }*/
  }

  ll ans = 0;
  Sort(v);
  rep(i, n) {
    if (i == 0) {
      ans++;
    } else {
      if (v[i] != v[i - 1]) {
        ans++;
      }
    }
  }

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


Error: TLE

Fixed submission:

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

typedef long long ll;
typedef int64_t i6;

#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep2(i, n) for (ll i = 1; i <= n; ++i)
#define ALL(v) (v).begin(), (v).end()
#define Sort(x) sort(ALL(x))
#define Sort_rev(x)                                                            \\
  Sort(x);                                                                     \\
  reverse(ALL(x))

template <typename V, typename T> T find_num(V v, T num) {
  if (find(ALL(v), num) == v.end()) {
    return false;
  } else {
    return true;
  }
}

// π M_PI
// deg = rad*180/M_PI

int main() {
  ll n;
  cin >> n;
  string s[n];
  ll ans = n;
  rep(i, n) {
    cin >> s[i];
    rep(j, i) {
      if (s[i] == s[j]) {
        ans--;
        break;
      }
    }
  }

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


Error: TLE

Fixed submission:

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

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

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
vector<bool> seen;
void dfs(const Graph &G, int v) {
  seen[v] = true; // vを訪問済みにする

  for (auto next_v : G[v]) {
    if (seen[next_v])
      continue;     // next_vが探索済みならスルー
    dfs(G, next_v); // 再帰的に探索
  }
}

int get_digit(ll n) {
  int digit = 0;
  if (n == 0) {
    return 1;
  }
  while (n != 0) {
    digit++;
    n /= 10;
  }
  return digit;
}
bool is_junretu(ll n) {
  int digit = get_digit(n);
  string s;
  s = to_string(n);
  bool flg = true;
  for (int i = 1; i <= digit; i++) {
    if (s.find(i) == string::npos) {
      flg = false;
      break;
    }
  }
  return flg;
}

int main() {

  int n;
  cin >> n;
  map<string, int> v;
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    if (v[s] == 0)
      cnt++;
    v[s] = 1;
  }
  cout << cnt << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
vector<bool> seen;
void dfs(const Graph &G, int v) {
  seen[v] = true; // vを訪問済みにする

  for (auto next_v : G[v]) {
    if (seen[next_v])
      continue;     // next_vが探索済みならスルー
    dfs(G, next_v); // 再帰的に探索
  }
}

int get_digit(ll n) {
  int digit = 0;
  if (n == 0) {
    return 1;
  }
  while (n != 0) {
    digit++;
    n /= 10;
  }
  return digit;
}
bool is_junretu(ll n) {
  int digit = get_digit(n);
  string s;
  s = to_string(n);
  bool flg = true;
  for (int i = 1; i <= digit; i++) {
    if (s.find(i) == string::npos) {
      flg = false;
      break;
    }
  }
  return flg;
}

int main() {

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

#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, 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 << endl;

  /*
  for(int i = 0; i < N; i++){
    cout << S[i] << endl; //文字列の配列が出来ているか確認
  }
  */

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, count = 0;

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

  count = N;

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

  for (int i = 0; i < N - 1; i++) {
    for (int j = i + 1; j < N; j++) {
      if (S[i] == S[j])
        S[j].erase(0);
    }
  }

  for (int i = 0; i < N; i++) {
    if (S[i].empty())
      count--;
  }

  cout << count << endl;

  /*
  for(int i = 0; i < N; i++){
    cout << S[i] << endl; //文字列の配列が出来ているか確認
  }
  */

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

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

int main() {
  int N = 0;
  cin >> N;
  // string syurui[200000]={};
  string temp = "";
  // int flag=0;
  int kosuu = 0;
  int i = 0;
  int j = 0;
  std::map<std::string, int> S;

  for (i = 0 /* 初期化 */; i < N /* 条件式 */; i++ /* 更新 */) {
    cin >> temp;
    /*for (j=0;j<kosuu;j++){
      if (temp == syurui[j]) {
        flag=1;
        break;
      }
    }
    if (flag == 0) {
      syurui[kosuu] = temp;
      kosuu++;
    }
    flag=0;*/
    S[temp]++;
  }
  for (auto itr = S.begin(); itr != S.end(); ++itr) {
    kosuu++;
  }
  cout << kosuu;
}

Error: TLE

Fixed submission:

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

int main() {
  int N = 0;
  cin >> N;
  string syurui[200000] = {};
  string temp = "";
  int flag = 0;
  int kosuu = 0;
  int i = 0;
  int j = 0;

  for (i = 0 /* 初期化 */; i < N /* 条件式 */; i++ /* 更新 */) {
    cin >> temp;
    for (j = 0; j < kosuu; j++) {
      if (temp == syurui[j]) {
        flag = 1;
        break;
      }
    }
    if (flag == 0) {
      syurui[kosuu] = temp;
      kosuu++;
    }
    flag = 0;
  }
  cout << kosuu;
}