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

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

typedef long long ll;

int main(void) {
  int i, t;
  cin >> t;
  string val;
  vector<string> name;
  for (i = 0; i < t; i++) {
    cin >> val;
    name.push_back(val);
  }

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

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

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

  return 0;
}


Error: TLE

Fixed submission:

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

typedef long long ll;

int main(void) {
  int i, t;
  cin >> t;
  string val;
  vector<string> name;
  for (i = 0; i < t; i++) {
    cin >> val;
    name.push_back(val);
  }

  sort(name.begin(), name.end());
  for (i = 0; i < t; i++) {
    name.erase(unique(name.begin(), name.end()), name.end());
  }

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

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

/*
 * WelcomeToAtCoder.cpp
 *
 *  Created on: 2020/02/19
 *      Author: black
 */
#include <algorithm>
#include <iostream>
#include <unordered_set>
#include <vector>
using namespace std;

int main() {
  int N;
  unordered_set<string> strList;
  string tmp;
  cin >> N;

  int count = 0;
  for (int i = 0; i < N; ++i) {
    cin >> tmp;
    if (strList.find(tmp) == strList.end()) {
      strList.insert(tmp);
      count++;
    }
  }

  cout << count << endl;

  return 0;
}


Error: TLE

Fixed submission:

/*
 * WelcomeToAtCoder.cpp
 *
 *  Created on: 2020/02/19
 *      Author: black
 */
#include <algorithm>
#include <iostream>
#include <unordered_set>
#include <vector>
using namespace std;

int main() {
  int N;
  unordered_set<string> strList;
  string tmp;
  cin >> N;

  int count = 0;
  for (int i = 0; i < N; ++i) {
    cin >> tmp;
    if (std::find(strList.begin(), strList.end(), tmp) == strList.end()) {
      strList.insert(tmp);
      count++;
    }
  }

  cout << count << endl;

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

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

void solve(int N) {
  int ans;
  ans = 0;
  string s_i, dup;
  vector<string> s;
  for (int i = 0; i < N; i++) {
    cin >> s_i;
    for (auto x : s) {
      if (x == s_i) {
        dup = x;
        break;
      }
    }
    if (dup == s_i) {
      continue;
    }
    s.push_back(s_i);
    ans++;
  }
  cout << ans << endl;
  return;
}

void solve_set(int N) {
  set<string> S;
  for (int i = 0; i < N; i++) {
    string s_i;
    cin >> s_i;
    S.insert(s_i);
  }
  cout << S.size() << endl;
  return;
}

int main() {
  int N;
  cin >> N;
  solve_set(N);
  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  int N, ans;
  ans = 0;
  cin >> N;
  string s_i, dup;
  vector<string> s;
  // rep(i, N){
  for (int i = 0; i < N; i++) {
    cin >> s_i;
    for (auto x : s) {
      if (x == s_i) {
        dup = x;
        break;
      }
    }
    if (dup == s_i) {
      continue;
    }
    s.push_back(s_i);
    ans++;
  }
  cout << ans << endl;
  return 0;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  map<int, queue<string>> kind;
  int sum = 0;
  set<string> str;
  for (int i = 0; i < N; i++) {
    string tmp;
    cin >> tmp;
    str.insert(tmp);
  }
  cout << str.size() << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  map<int, queue<string>> kind;
  int sum = 0;
  for (int i = 0; i < N; i++) {
    string tmp;
    cin >> tmp;
    int st_sum = 0;
    bool check = true;
    auto memo = kind;
    for (int j = 0; j < tmp.size(); j++) {

      st_sum += (int)(tmp.at(j));
    }

    while (!kind[st_sum].empty()) {
      if (kind[st_sum].front() == tmp) {
        check = false;
        break;
      }
      kind[st_sum].pop();
    }
    kind = memo;
    if (check) {
      sum++;
      kind[st_sum].push(tmp);
    }
  }
  cout << sum << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int N = 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() << 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 <iostream>
#include <vector>
using namespace std;
int main() {
  int i, j, n, c = 0;
  vector<string> v(n);
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> v[i];
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < i; j++) {
      if (v[i] == v[j])
        break;
    }
    if (i == j)
      c++;
  }
  cout << c;
  return 0;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

  int i, j;
  int c;
  i = 0;
  j = 1;
  c = 0;
  sort(S.begin(), S.end());
  // for(int i=0;i<N;++i) cout<<S[i]<<endl;
  while (true) {
    while (S[i] == S[j]) {
      c++;
      j++;
    }
    if (j >= N)
      break;
    i = j;
    j = i + 1;
  }

  cout << N - c << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  int N, n;
  cin >> N;
  int c, c1;
  vector<string> S(N);
  for (int i = 0; i < N; ++i) {
    cin >> S[i];
    // cout<<S[i]<<endl;
  }
  c = 0;
  n = N;
  for (int i = 0; i < N - 1; ++i) {
    c1 = 0;
    if (S[i][0] == 0)
      continue;
    for (int j = i + 1; j < N; ++j) {
      if (S[i] == S[j]) {
        c1++;
        S[j][0] = 0;
        // cout<<i<<" "<<j<<" "<<n<<endl;
      }
    }
    c = c + c1;
  }
  cout << N - c << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using ll = long long int;
using namespace std;
ll mod = 1e9 + 7;

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

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using ll = long long int;
using namespace std;
ll mod = 1e9 + 7;

int main() {
  int n;
  cin >> n;
  string s[n];
  for (int i = 0; i < n; i++)
    cin >> s[i];
  int ans = n;
  for (int i = 0; i < n; i++) {
    for (int r = i + 1; r < n; r++) {
      if (s[i] == s[r]) {
        ans--;
        break;
      }
    }
  }
  cout << ans << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n, c = 1;
  cin >> n;
  vector<string> t(n);
  for (int i = 0; i < n; ++i)
    cin >> t[i];
  sort(t.begin(), t.end());
  for (int i = 1; i < n; ++i) {
    if (t[i] != t[i - 1])
      ++c;
  }
  cout << c;
}

Error: TLE

Fixed submission:

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

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

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main() {
  ll n, sum = 0;
  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] != s[i - 1])
      sum++;
  }
  cout << sum + 1 << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

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

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

using namespace std;

int main() {
  int N, c = 0;
  cin >> N;
  map<string, int> mp;
  for (int i = 0; i < N; i++) {
    string input;
    cin >> input;
    mp[input] = 1;
  }
  cout << mp.size() << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

using namespace std;

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

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

int main() {
  int N, count;

  cin >> N;
  count = 1;
  vector<string> K(N);
  for (int i = 0; i < N; i++) {
    cin >> K.at(i);
  }

  sort(K.begin(), K.end());
  for (int i = 0; i < N - 1; i++) {
    if (K.at(i) == K.at(i + 1)) {
      continue;
    }
    count++;
  }
  cout << count << endl;
}


Error: TLE

Fixed submission:

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

int main() {
  int N, count, count2, m;
  string M;
  count = 0;
  // count2=0;
  cin >> N;
  vector<string> K(N);
  vector<int> KK(N);
  for (int i = 0; i < N; i++) {
    cin >> K.at(i);
    M = K.at(i);
    for (int j = 0; j < N; j++) {
      if (i < j) {
        continue;
      }
      if (M == K.at(j) && i != j) {
        KK.at(i) = 1;
        KK.at(j) = 0;

      } else {
        KK.at(i) = 1;
      }
    }
  }
  for (int i = 0; i < N; i++) {
    if (KK.at(i) == 1) {
      count++;
    }
  }
  cout << count << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int, int>
#define vvi vector<vi>
#define vvl vector<vl>
#define all(x) x.begin(), x.end()
#define contains(con, x) con.find(x) != con.end()
#define fastread ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)

int main() {
  fastread;

  int T = 1;
  // cin >> T;

  while (T--) {
    int N;
    cin >> N;

    vector<string> s(N);
    set<string> uniq;
    for (int i = 0; i < N; i++) {
      cin >> s[i];
      uniq.insert(s[i]);
    }
    cout << uniq.size() << '\\n';
  }
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int, int>
#define vvi vector<vi>
#define vvl vector<vl>
#define all(x) x.begin(), x.end()
#define contains(con, x) con.find(x) != con.end()
#define fastread ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)

int main() {
  fastread;

  int T = 1;
  // cin >> T;

  while (T--) {
    int N;
    cin >> N;

    vector<string> s;
    set<string> uniq;
    for (int i = 0; i < N; i++) {
      cin >> s[i];
      uniq.insert(s[i]);
    }
    cout << uniq.size() << '\\n';
  }
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  set<string> s;
  while (n--) {
    string t;
    cin >> t;
    s.insert(t);
  }
  cout << s.size() << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
string s[1000005];
int x;
int main() {
  cin >> x;
  int h = 0, cnt = 0;
  for (int i = 0; i < x; i++) {
    string f;
    cin >> f;
    bool b = true;
    for (int j = 0; j < i; j++) {
      if (f == s[j])
        b = false;
    }
    if (b == true) {
      s[h] = f;
      h++;
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n, i, same = 0;
  ;
  cin >> n;
  string str[n];

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

  sort(str, str + n);

  for (i = 0; i < n - 1; i++) {
    if (str[i] == str[i + 1]) {
      same++;
    }
  }

  cout << n - same << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int n, i, j, flag = 0, sum = 0;
  ;
  cin >> n;
  string str[n];

  for (i = 0; i < n; i++) {
    cin >> str[i];
    for (j = 0; j < i; j++) {
      if (str[i] == str[j]) {
        flag = 1;
        break;
      }
    }
    if (flag == 0) {
      sum++;
    } else {
      flag = 0;
    }
  }

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

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;

#define rep(i, N) for (int i = 0; i < (int)N; i++)
#define all(v) (v).begin(), (v).end()

const int INF = 100000002;

int main() {
  ll n;
  cin >> n;
  map<string, int> d;
  ll ans = 0;
  rep(i, n) {
    string s;
    cin >> s;
    d[s] += 1;
  }
  cout << (int)d.size() << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;

#define rep(i, N) for (int i = 0; i < (int)N; i++)
#define all(v) (v).begin(), (v).end()

const int INF = 100000002;

int main() {
  ll n;
  cin >> n;
  vector<string> d(n);
  ll ans = 0;
  rep(i, n) {
    string s;
    cin >> s;
    if (count(d.begin(), d.end(), s))
      continue;
    else {
      d[ans] = s;
      ans++;
    }
  }
  cout << ans << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <set>
#include <string>
using namespace std;
int main() {
  int n;
  cin >> n;
  set<string> result;
  for (int i = 0; i < n; i++) {
    string str;
    cin >> str;
    result.insert(str);
  }
  cout << result.size() << "\\n";
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
  int N;
  cin >> N;
  string result[N];
  int count = 0;
  bool flag = false;
  for (int i = 0; i < N; i++) {
    string temp;
    cin >> temp;
    result[i] = temp;
    for (int j = i; j > 0; j--) {
      if (j == 0 || result[j - 1] == temp) {
        flag = true;
        break;
      }
    }
    if (flag == false) {
      count += 1;
    }
    flag = false;
  }

  cout << count << "\\n";
  return 0;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

//
//  main.cpp
//  C - gacha
//
//  Created by Hashizo on 2020/04/26.
//  Copyright © 2020 Hashizo. All rights reserved.
//

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

using namespace std;

#undef LONG_MAX
#undef LONG_MIN

#define LONG_MAX 9223372036854775807
#define LONG_MIN (-LONG_MAX - 1)

#define ll long long

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)

#define SORT(c) sort((c).begin(), (c).end())
#define REVERSE(v) reverse((v).begin(), (v).end())

int main(int argc, const char *argv[]) {
  ll ans = 1;

  ll n;
  cin >> n;

  vector<string> gacha(n);

  REP(i, n) { cin >> gacha[i]; }

  SORT(gacha);

  REP(i, n - 1) {
    if (gacha[i] != gacha[i + 1]) {
      ans++;
    }
  }

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


Error: TLE

Fixed submission:

//
//  main.cpp
//  C - gacha
//
//  Created by Hashizo on 2020/04/26.
//  Copyright © 2020 Hashizo. All rights reserved.
//

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

using namespace std;

#undef LONG_MAX
#undef LONG_MIN

#define LONG_MAX 9223372036854775807
#define LONG_MIN (-LONG_MAX - 1)

#define ll long long

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)

#define SORT(c) sort((c).begin(), (c).end())
#define REVERSE(v) reverse((v).begin(), (v).end())

int main(int argc, const char *argv[]) {
  ll ans = 1;

  ll n;
  cin >> n;

  vector<string> gacha;

  string s;
  cin >> s;
  gacha.push_back(s);

  bool same = false;
  REP(i, n - 1) {
    cin >> s;
    REP(j, gacha.size()) {
      if (gacha[j] == s) {
        same = true;
        break;
      }
    }
    if (same == false) {
      ans++;
      gacha.push_back(s);
    }
    same = false;
  }

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

#include <bits/stdc++.h>
using namespace std;
bool cmp(string a, string b) {
  return a <= b;
  ;
}
int main() {
  string cc[200010];
  int n, i, j, k, l, cnt = 1;
  cin >> n;
  for (i = 1; i <= n; i++)
    cin >> cc[i];
  sort(cc + 1, cc + 1 + n);
  for (i = 2; i <= n; i++) {
    if (cc[i] != cc[i - 1])
      cnt++;
  }
  cout << cnt;
  getchar();
  getchar();
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
bool cmp(char a[], char b[]) {
  if (strcmp(a, b) <= 0)
    return true;
  return false;
}
int main() {
  char cc[200010][15];
  int n, i, j, k, l, cnt = 1;
  cin >> n;
  for (i = 1; i <= n; i++)
    scanf("%s", cc[i]);
  for (i = 2; i <= n; i++) {
    for (j = 1; j < i; j++) {
      if (strcmp(cc[i], cc[j]) == 0)
        break;
    }
    if (j == i)
      cnt++;
  }
  cout << cnt;
  getchar();
  getchar();
}
Problem p02701 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int N;
  cin >> N;
  vector<string> S(N);
  int count = 0;
  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;
}


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;

int main() {
  int N;
  cin >> N;
  vector<string> S(N);
  int count = 0;
  for (int i = 0; i < N; i++) {
    cin >> S.at(i);
  }
  for (int i = 0; i < N - 1; i++) {
    for (int j = i + 1; i < N; j++) {
      if (S.at(i) == S.at(j))
        count++;
    }
  }
  cout << N - 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;
using ll = long long;
using P = pair<int, int>;

int main() {
  int N;
  cin >> N;
  vector<string> S;

  rep(i, N) {
    string s;
    cin >> s;
    S.push_back(s);
  }

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

  int ans = 1;
  string now = S[0];
  rep(i, N) {
    if (S[i] != now) {
      ans++;
      now = S[i];
    }
  }

  cout << ans << 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() {
  int N;
  cin >> N;
  vector<string> S;

  int ans = 0;
  rep(i, N) {
    string s;
    cin >> s;
    int flag = 0;
    rep(j, S.size()) {
      // cout << S[j] << " " << s << endl;
      if (S[j] == s)
        flag = 1;
    }
    if (flag == 0) {
      ans++;
      S.push_back(s);
    }
  }

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

#include <bits/stdc++.h>
using namespace std;
map<string, int> mp;
int n, ans;
string s;

int main() {
  cin >> n;

  while (n--) {
    cin >> s;
    mp[s] = 1;
  }

  for (map<string, int>::iterator it = mp.begin(); it != mp.end(); it++)
    ans++;
  cout << ans;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
string s[2 * 100000 + 5];
int n, i, j, ans;

int main() {
  cin >> n;

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

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

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

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

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

  sort(s, s + n);

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

  cout << ans;
}

Error: WA

Fixed submission:

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

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

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

  sort(s, s + n);

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

  cout << ans;
}
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> kname(n, "0");

  string tmp;

  for (int i = 0; i < n; ++i) {
    cin >> tmp;
    kname.at(i) = tmp;
  }
  std::sort(kname.begin(), kname.end());
  kname.erase(std::unique(kname.begin(), kname.end()), kname.end());
  cout << kname.size() << endl;

  return 0;
}


Error: TLE

Fixed submission:

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

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

  unordered_set<string> kname;

  string tmp;

  for (int i = 0; i < n; ++i) {
    cin >> tmp;
    auto missing = std::find(kname.begin(), kname.end(), tmp);
    if (missing == kname.end()) {
      kname.insert(tmp);
    }
  }

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

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

#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(void) {
  int n;
  cin >> n;
  string tmps;
  vector<string> s[26][26];
  vector<string> s1;
  for (int i(0); i < n; i++) {
    cin >> tmps;
    bool newpresent(true);
    if (tmps.size() == 1) {
      for (int j(0); j < s1.size(); j++) {
        if (tmps == s1[j])
          newpresent = false;
      }
      if (newpresent)
        s1.push_back(tmps);
    } else {
      for (int j(0); j < s[(int)tmps[0] - 97][(int)tmps[1] - 97].size(); j++) {
        if (tmps == s[(int)tmps[0] - 97][(int)tmps[1] - 97][j]) {
          newpresent = false;
          break;
        }
      }
      if (newpresent)
        s[(int)tmps[0] - 97][(int)tmps[1] - 97].push_back(tmps);
    }
  }
  int presentnum(s1.size());
  for (int i(0); i < 26; i++) {
    for (int j(0); j < 26; j++) {
      presentnum += s[i][j].size();
    }
  }
  cout << presentnum << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(void) {
  int n;
  cin >> n;
  string tmps;
  vector<string> s[26][26];
  for (int i(0); i < n; i++) {
    cin >> tmps;
    bool newpresent(true);
    for (int j(0); j < s[(int)tmps[0] - 97][(int)tmps[1] - 97].size(); j++) {
      if (tmps == s[(int)tmps[0] - 97][(int)tmps[1] - 97][j]) {
        newpresent = false;
        break;
      }
    }
    if (newpresent)
      s[(int)tmps[0] - 97][(int)tmps[1] - 97].push_back(tmps);
  }
  int presentnum(0);
  for (int i(0); i < 26; i++) {
    for (int j(0); j < 26; j++) {
      presentnum += s[i][j].size();
    }
  }
  cout << presentnum << endl;
  return 0;
}