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(N);

  for (int i = 0; i < N; i++)
    cin >> S.at(i);

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

  int cnt = 0;

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

  cout << N - cnt << 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 cnt = 0;

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

    for (int j = i + 1; j < N; j++) {
      if (S.at(i) == S.at(j)) {
        cnt++;
        break;
      }
    }
  }

  cout << N - cnt << 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> v;
  int i, j, k, l, m;
  for (i = 0; i < n; i++) {
    string str;
    cin >> str;

    v.insert(str);
  }
  cout << v.size();
}


Error: TLE

Fixed submission:

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

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

int main() {
  int n;
  int count;

  cin >> n;

  count = n;

  vector<string> data(n);

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

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

  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;
  string s;
  int count = 0;
  bool flag;

  cin >> n;

  vector<string> data(n);

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

    flag = true;

    for (int j = 0; j < count; j++) {
      if (data.at(j) == s)
        flag = false;
    }

    if (flag) {
      data.at(count) = '\\0';
      data.at(count) = s;
      count++;
    }
  }

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

#include <algorithm>
#include <iostream>
#include <set>
#include <string>
using namespace std;
string ch;
set<string> s;
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> ch;
    s.insert(ch);
  }
  int sum = 0;
  sum = s.size();
  cout << sum;
  return 0;
  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <iostream>
#include <set>
#include <string>
using namespace std;
string ch[20005];
set<string> s;
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> ch[i];
    s.insert(ch[i]);
  }
  int sum = 0;
  sum = s.size();
  cout << sum;
  return 0;
  return 0;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  set<string> v;
  int n, i;
  cin >> n;
  for (i = 1; i <= n; i++) {
    string x;
    cin >> x;
    v.insert(x);
  }

  cout << v.size();
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int n, i, m = 1;
  cin >> n;
  string a[n + 1];
  cin >> a[1];
  for (i = 2; i <= n; i++) {
    string x;
    cin >> x;
    bool c = 0;
    for (int j = 1; j <= m; j++)
      if (a[j] == x) {
        c = 1;
        break;
      }
    if (c == 0) {
      m++;
      a[m] = x;
      //			cout<<i<<endl;
    }
  }
  cout << m;
  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;
typedef long long ll;
const int MOD = 1E9 + 7;
const int INF = 1 << 29;

int main() {
  int N;
  cin >> N;
  string tmp;
  map<string, int> S;
  rep(i, N) {
    cin >> tmp;
    S[tmp]++;
  }
  cout << S.size() << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
const int MOD = 1E9 + 7;
const int INF = 1 << 29;

int main() {
  int N;
  cin >> N;
  string tmp;
  int cnt = 0;
  vector<string> S(N);
  int ans = 0;
  bool flag = false;
  rep(i, N) {
    cin >> tmp;
    flag = false;
    rep(j, cnt) {
      if (S[j] == tmp) {
        flag = true;
        break;
      };
    }
    if (!flag) {
      S[cnt] = tmp;
      cnt++;
      ans++;
    };
  };
  cout << ans << endl;
  return 0;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ull unsigned long long int
#define IOS                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mx *max_element
#define mn *min_element
#define fo(i, n) for (ll i = 0; i < n; i++)
#define of(i, n) for (ll i = n - 1; i >= 0; i--)
#define all(x) x.begin(), x.end()
#define sortall(x) sort(all(x))
#define mem(x, p) memset(x, p, sizeof(x))
#define w(t)                                                                   \\
  ll t;                                                                        \\
  cin >> t;                                                                    \\
  while (t--)
#define kk "\\n"
const ll mod = 1e9 + 7;
int main() {
  IOS ll n;
  cin >> n;
  ll p = 31;
  ll c = 0;
  unordered_map<ll, ll> mp{0};
  fo(i, n) {
    string s;
    cin >> s;
    ll ans = 0;
    for (ll j = 0; j < s.length(); j++) {
      ll c = (ll)(s[j]);
      ans = ans + (ll)((c * (ll)pow(p, (ll)(j + 1))));
    }
    if (mp[ans] == 0) {
      c++;
      mp[ans] = 1;
    }
  }
  cout << c << kk;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ull unsigned long long int
#define IOS                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mx *max_element
#define mn *min_element
#define fo(i, n) for (ll i = 0; i < n; i++)
#define of(i, n) for (ll i = n - 1; i >= 0; i--)
#define all(x) x.begin(), x.end()
#define sortall(x) sort(all(x))
#define mem(x, p) memset(x, p, sizeof(x))
#define w(t)                                                                   \\
  ll t;                                                                        \\
  cin >> t;                                                                    \\
  while (t--)
#define kk "\\n"
const ll mod = 1e9 + 7;
int main() {
  IOS ll n;
  cin >> n;
  ll p = 23;
  ll c = 0;
  string s[n];
  fo(i, n) cin >> s[i];
  fo(i, n) {
    ll f = 0;
    for (ll j = 0; j < i; j++) {
      if (s[i].length() != s[j].length())
        continue;
      else {
        ll h = 0;
        for (ll k = 0; k < s[i].length(); k++) {
          if (s[j][k] != s[i][k]) {
            h = 1;
            break;
          }
        }
        if (h == 0) {
          f = 1;
          break;
        }
      }
    }
    if (!f)
      c++;
  }
  cout << c << kk;
  return 0;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define lli long long int
#define rep(i, n) for (lli i = 0; i < n; i++)
#define loop(i, j, n) for (lli i = j; i < n; i++)
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) < (b) ? (a) : (b))
constexpr int INF = 0x3f3f3f3f;
const long long mod = 1e9 + 7;
// Function
lli combi(lli n, lli r) {
  if (r == 0 || r == n)
    return 1;
  else
    return combi(n - 1, r) + combi(n - 1, r - 1);
}
lli sigma1(lli n) { return n * (n + 1) / 2; }
lli sigma2(lli s, lli n) { return sigma1(n) - sigma1(s - 1); }
using namespace std;
// }}} End Header

lli body(lli a, lli b) { return (a - b) * (a - b); }
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  lli n;
  cin >> n;
  vector<string> ss(n);
  set<string> t;
  rep(i, n) {
    cin >> ss[i];
    t.insert(ss[i]);
  }
  cout << t.size() << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define lli long long int
#define rep(i, n) for (lli i = 0; i < n; i++)
#define loop(i, j, n) for (lli i = j; i < n; i++)
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) < (b) ? (a) : (b))
constexpr int INF = 0x3f3f3f3f;
const long long mod = 1e9 + 7;
// Function
lli combi(lli n, lli r) {
  if (r == 0 || r == n)
    return 1;
  else
    return combi(n - 1, r) + combi(n - 1, r - 1);
}
lli sigma1(lli n) { return n * (n + 1) / 2; }
lli sigma2(lli s, lli n) { return sigma1(n) - sigma1(s - 1); }
using namespace std;
// }}} End Header

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  lli n;
  cin >> n;
  vector<string> s;
  string t;
  cin >> t;
  s.push_back(t);
  loop(i, 1, n) {
    string ss;
    cin >> ss;
    bool ans = true;
    lli k1 = s.size();
    rep(l, k1) {
      if (s[l] == ss) {
        ans = false;
        break;
      }
    }
    if (ans)
      s.push_back(ss);
  }
  lli k2 = s.size();
  cout << k2 << endl;
  return 0;
}
Problem p02701 (C++) — buggy submission, verdict: Runtime Error


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

#define TABLE_LEN 1048575
#define TABLE_COL 16
long long int StrtoInt[TABLE_LEN][TABLE_COL];

long long int Convert(char *Str) {
  long long int Result = 0;
  for (int i = 0; i < strlen(Str); i++) {
    Result += (Str[i] - 'a' + 1);
    Result *= ('z' - 'a' + 1);
  }

  return Result;
}

int main() {
  char Str[128];

#ifdef _WIN32
  freopen("input.txt", "r", stdin);
#endif

  int N;
  scanf("%d", &N);
  int Result = 0;
  for (int n = 0; n < N; n++) {
    scanf("%s", Str);
    long long int StrVal = Convert(Str);
    long long int Hash = StrVal % TABLE_LEN;

    for (int i = 0; i < TABLE_COL; i++)
      if ((StrVal == StrtoInt[Hash][i]))
        break;
      else if (StrtoInt[Hash][i] == 0) {
        StrtoInt[Hash][i] = StrVal;
        Result++;
        break;
      }
  }

  printf("%d", Result);
  return 0;
}

Error: -11

Fixed submission:


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

#define TABLE_LEN 200000001
unsigned char StrtoInt[TABLE_LEN];

long long int Convert(char *Str) {
  long long int Result = 0;
  for (int i = 0; i < strlen(Str); i++) {
    Result += (Str[i] - 'a');
    Result *= ('z' - 'a' + 1);
  }

  return Result;
}

int main() {
  char Str[128];

#ifdef _WIN32
  freopen("input.txt", "r", stdin);
#endif

  int N;
  scanf("%d", &N);

  for (int n = 0; n < N; n++) {
    scanf("%s", Str);
    StrtoInt[Convert(Str)] = 1;
  }

  int Result = 0;
  for (long long int t = 0; t < TABLE_LEN; t++)
    Result += StrtoInt[t];

  printf("%d", Result);
  return 0;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
using Graph = vector<vector<int>>;
// MOD
const int MOD = 1000000007;

long long GCD(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return GCD(b, a % b);
}

int H, W;
int field[100][100];

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const double PI = 3.14159265358979323846;
bool seen[100][100];

string N[100];

bool memo[110];
bool flag;
Graph G;

int dist[100][100];

void dfs(int v, vector<bool> &seen, int &res) {
  bool end = true;
  for (int i = 0; i < seen.size(); ++i)
    if (!seen[i] && i != v)
      end = false;
  if (end) {
    ++res;
    return;
  }

  seen[v] = true;
  for (auto nv : G[v]) {
    if (seen[nv])
      continue;
    dfs(nv, seen, res);
  }
  seen[v] = false;
}
bool compare_f(pair<int, int> &x, pair<int, int> &y) {
  return x.second < y.second;
}

int dp[100000];

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

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
using Graph = vector<vector<int>>;
// MOD
const int MOD = 1000000007;

long long GCD(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return GCD(b, a % b);
}

int H, W;
int field[100][100];

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const double PI = 3.14159265358979323846;
bool seen[100][100];

string N[100];

bool memo[110];
bool flag;
Graph G;

int dist[100][100];

void dfs(int v, vector<bool> &seen, int &res) {
  bool end = true;
  for (int i = 0; i < seen.size(); ++i)
    if (!seen[i] && i != v)
      end = false;
  if (end) {
    ++res;
    return;
  }

  seen[v] = true;
  for (auto nv : G[v]) {
    if (seen[nv])
      continue;
    dfs(nv, seen, res);
  }
  seen[v] = false;
}
bool compare_f(pair<int, int> &x, pair<int, int> &y) {
  return x.second < y.second;
}

int dp[100000];

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

  int res = 0;
  for (int i = 0; i < n; i++) {
    bool ans = false;
    for (int j = i + 1; j < n; j++) {
      if (s[i] == s[j])
        ans = true;
    }
    if (!ans)
      res++;
  }
  cout << res << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Runtime Error

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

using namespace std;
using ll = long long;

int main(void) {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  ll n;
  cin >> n;
  set<string> s;
  rep(i, n) {
    string a;
    cin >> a;
    s.insert(a);
  }
  cout << s.size() << endl;

  return 0;
}


Error: 0

Fixed submission:

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

using namespace std;
using ll = long long;

int main(void) {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  ll n;
  cin >> n;
  vector<string> s;
  rep(i, n) {
    string a;
    cin >> a;
    int t = 1;
    for (int j = 0; j < i; ++j) {
      if (s[j] == a)
        t = 0;
    }
    if (t)
      s.push_back(a);
  }
  cout << s.size() << endl;

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

#include <bits/stdc++.h>
using namespace std;
int N;
string a[200001];
map<string, int> mp;
int ans = 0;

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

  for (int i = 0; i < N; i++) {
    mp[a[i]] = 1;
  }

  for (auto i = mp.begin(); i != mp.end(); ++i) {
    ans += i->second;
  }
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef float fl;
typedef long long ll;
int N;
string a[20001];
map<string, int> mp;
int ans = 0;

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

  for (int i = 0; i < N; i++) {
    mp[a[i]] = 1;
  }

  for (auto i = mp.begin(); i != mp.end(); ++i) {
    ans += i->second;
  }
  cout << ans << endl;
  return 0;
}
Problem p02701 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<string> s[26][26];
  int single[26];
  string si;
  for (int i = 0; i < n; i++) {

    cin >> si;
    bool first = true;
    if (si.size() == 1) {
      single[si[0] - 'a'] = 1;
    } else {
      for (int j = 0; j < s[si[0] - 'a'][si[1] - 'a'].size(); j++) {
        if (si == s[si[0] - 'a'][si[1] - 'a'][j])
          first = false;
      }
      if (first)
        s[si[0] - 'a'][si[1] - 'a'].push_back(si);
    }
  }
  int sum = 0;
  for (int j = 0; j < 26; j++) {
    for (int i = 0; i < 26; i++) {
      sum += s[j][i].size();
    }
    sum += single[j];
  }

  cout << sum << endl;
}


Error: 0

Fixed submission:

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

    cin >> si;
    bool first = true;
    for (int j = 0; j < s[si[0] - 'a'][si[1] - 'a'].size(); j++) {
      if (si == s[si[0] - 'a'][si[1] - 'a'][j])
        first = false;
    }
    if (first)
      s[si[0] - 'a'][si[1] - 'a'].push_back(si);
  }
  int sum = 0;
  for (int j = 0; j < 26; j++) {
    for (int i = 0; i < 26; i++) {
      sum += s[j][i].size();
    }
  }

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

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

using namespace std;

int main() {
  int N;
  cin >> N;
  vector<string> cand = {};
  string tmp;
  for (int i = 0; i < N; ++i) {
    cin >> tmp;
    cand.push_back(tmp);
  }
  sort(cand.begin(), cand.end());
  decltype(cand)::iterator result = unique(cand.begin(), cand.end());
  cand.erase(result, cand.end());
  cout << cand.size() << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;

int main() {
  int N;
  cin >> N;
  string S[N];
  vector<string> cand = {};
  for (int i = 0; i < N; ++i) {
    cin >> S[i];
  }
  for (int i = 0; i < N; ++i) {
    bool flag = true;
    for (int j = 0; j < cand.size(); ++j) {
      if (S[i] == cand[j]) {
        flag = false;
        break;
      }
    }
    if (flag)
      cand.push_back(S[i]);
  }
  cout << cand.size() << endl;

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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

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

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

int main(void) {
  ll N;
  cin >> N;
  vector<string> S(N);
  REP(i, N) cin >> S[i];
  ll ans = 1, temp = 1;
  vector<string> a(N);
  a[0] = S[0];
  FOR(i, 1, N) {
    bool exist = true;
    REP(j, temp) {
      if (a[j] == S[i]) {

        exist = false;
      }
    }
    if (exist) {
      ans++;
      temp++;
      a[temp] = S[i];
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define rep(i, n) for (long long i = 0; i < n; i++)
using ll = long long;
const ll INF = (1LL << 60);

int main() {

  ll n;
  cin >> n;

  string in;
  map<string, ll> mp;

  rep(i, n) {
    cin >> in;
    mp[in] = 1;
  }

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

  return 0;
}

Error: TLE

Fixed submission:

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

#define rep(i, n) for (long long i = 0; i < n; i++)
using ll = long long;
const ll INF = (1LL << 60);

int main() {

  ll n;
  cin >> n;
  vector<string> a;

  string in;
  cin >> in;
  a.push_back(in);

  bool f;
  for (ll i = 1; i < n; i++) {
    f = false;
    cin >> in;
    rep(j, a.size()) {
      if (in == a[j])
        f = true;
      if (f)
        break;
    }
    if (f)
      continue;
    a.push_back(in);
  }

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

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

#include <bits/stdc++.h>

using namespace std;

int main() {
  cin.tie(0);
  cin.sync_with_stdio(0);
  long long n, co = 1;
  cin >> n;
  vector<string> v;
  while (n--) {
    string s;
    cin >> s;
    v.push_back(s);
  }
  sort(v.begin(), v.end());
  for (int i = 1; i < v.size(); i++) {
    if (v[i] != v[i - 1])
      co++;
  }
  cout << co;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main() {
  cin.tie(0);
  cin.sync_with_stdio(0);
  long long n;
  cin >> n;
  vector<string> v;
  while (n--) {
    string s;
    cin >> s;
    int c = 0;
    for (int i = 0; i < v.size(); i++) {
      if (v[i] == s) {
        c++;
        break;
      }
    }
    if (c == 0) {
      v.push_back(s);
    }
  }
  cout << v.size();
  return 0;
}
Problem p02701 (C++) — buggy submission, verdict: Runtime Error

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

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  string s[100000];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  sort(s, s + n);
  int ans = 1;
  for (int i = 1; i < n; i++) {
    if (s[i] != s[i - 1]) {
      ans++;
    }
  }
  cout << ans << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

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

  int ans = 1;
  sort(v.begin(), v.end());
  queue<string> q;
  q.push(v.at(0));

  for (int i = 0; i < n; i++) {
    if (q.front() != v.at(i)) {
      q.push(v.at(i));
      q.pop();
      ans++;
    }
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

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

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

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

  int ans = 1;
  sort(v.begin(), v.end());

  int i = 0;
  while (v.size() != 1) {
    if (v.at(i) != v.at(i + 1)) {
      ans++;
    }
    v.erase(v.begin());
  }
  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;
  map<string, bool> exist;
  int count = 0;
  for (int i = 0; i < N; i++) {
    string S;
    cin >> S;
    if (!exist[S]) {
      exist[S] = true;
      count += 1;
    }
  }
  cout << count << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  int N;
  cin >> N;
  vector<string> list(N);
  int count = 0;
  for (int i = 0; i < N; i++) {
    string S;
    cin >> S;
    bool original = true;
    list[i] = S;
    for (int j = 0; j < i; j++) {
      if (list[j] == S) {
        original = false;
      }
    }
    if (original) {
      count += 1;
    }
  }
  cout << count << endl;
}