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



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

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

  vector<string> v_s(n);
  for (int i = 0; i < n; i++) {
    cin >> v_s[i];
  }

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

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

  cout << count << endl;

  return 0;
}


Error: TLE

Fixed submission:



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

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

  vector<string> v_s;
  v_s.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> v_s[i];
  }

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

  for (int i = 0; i < v_s.size() - 1; i++) {

    for (int j = i + 1; j < v_s.size(); j++) {

      if (v_s[i] == v_s[j]) {
        v_s.erase(v_s.begin() + j);
        j -= 1;
      }
    }
  }

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

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

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

int main() {
  int n, i, j;
  int count = 1;
  cin >> n;

  vector<string> vec(n);

  for (i = 0; i < n; i++) {
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  vec.erase(unique(vec.begin(), vec.end()), vec.end());

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

Error: TLE

Fixed submission:

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

int main() {
  int n, i, j;
  int count = 1;
  cin >> n;

  vector<string> kehin(n);
  vector<string> tmp(n);

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

  tmp.at(0) = kehin.at(0);

  for (i = 1; i < n; i++) {
    for (j = 0; j < count; j++) {
      if (tmp.at(j) == kehin.at(i)) {
        break;
      }
    }
    if (j == count) {
      tmp.at(count) = kehin.at(i);
      count++;
    }
  }
  cout << count << endl;
  return 0;
}
Problem p02701 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#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++)
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl
#define no cout << "no" << endl
#define vec(a, y, x) vector<vector<char>> a(y, vector<char>(x))
const double PI = 3.14159265358979323846;
const in MOD = 1000000007;
const in INF = 1e18 + 7;
const int inf = 1e9 + 7;
const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};

int main() {
  int n;
  cin >> n;
  vector<string> num = {};
  int ans = 1;
  rep(i, n) {
    string a;
    cin >> a;

    num.push_back(a);
  }
  sort(all(num));
  for (int i = 1; i < n; i++) {
    if (num.at(i - 1) != num.at(i))
      ans++;
  }
  cout << ans << endl;
}

Error: -6
terminate called after throwing an instance of 'std::out_of_range'
  what():  vector::_M_range_check: __n (which is 2) >= this->size() (which is 2)


Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#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++)
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl
#define no cout << "no" << endl
#define vec(a, y, x) vector<vector<char>> a(y, vector<char>(x))
const double PI = 3.14159265358979323846;
const in MOD = 1000000007;
const in INF = 1e18 + 7;
const int inf = 1e9 + 7;
const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};

int main() {
  int n;
  cin >> n;
  vector<string> num = {};
  int ans = 1;
  rep(i, n) {
    string a;
    cin >> a;
    if (find(all(num), a) == num.end()) {
      // ans++;
      num.push_back(a);
      // sort(all(num));
    }
  }
  sort(all(num));
  for (int i = 1; i < n; i++) {
    if (num.at(i - 1) != num.at(i))
      ans++;
  }
  cout << ans << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int64_t N, count = 1;
  string S;
  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 = 1; i < N; i++) {
    // cout << i << " " << vec.at(i);
    if (vec.at(i - 1) != vec.at(i))
      count++;
    // cout << count << endl;
  }
  cout << count << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  int64_t N, count = 1;
  string S;
  cin >> N;
  vector<string> vec(N);

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

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

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

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

  return 0;
}

Error: TLE

Fixed submission:

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

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

  vector<string> s;
  string memo;
  cin >> memo;
  s.push_back(memo);
  for (int i = 1; i < n; i++) {
    cin >> memo;
    for (int j = 0; j < s.size(); j++) {
      if (memo == s[j]) {
        break;
      }
      if (j == s.size() - 1) {
        s.push_back(memo);

        break;
      }
    }
  }

  cout << s.size();
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long int lli;

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

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long int lli;

int main() {
  int N;
  cin >> N;
  vector<string> S;
  for (int i = 0; i < N; i++) {
    string sn;
    cin >> sn;
    auto result = find(S.begin(), S.end(), sn);
    if (result == S.end()) {
      S.push_back(sn);
    }
  }
  cout << S.size() << endl;
  return 0;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

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

long long n;
string x;
set<string> s;

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


Error: TLE

Fixed submission:

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

long long n;
string s[200005], a[200005];

int main() {
  cin >> n;
  int idx = 1;
  for (int i = 1; i <= n; i++) {
    cin >> s[i];
    for (int j = 1; j <= idx + 1; j++) {
      if (j == idx + 1) {
        idx++;
        a[idx] = s[i];
      }
      if (s[i] == a[j]) {
        break;
      }
      // cout<<idx-1<<endl;
    }
  }
  cout << idx - 1 << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Runtime Error

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

vector<string> a;
int n, cnt = 1;
string x;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  while (n--)
    cin >> x, a.push_back(x);
  sort(a.begin(), a.end());
  cout << unique(a.begin(), a.end()) - a.begin();
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
using namespace std;
typedef unsigned long long ull;
const ull mod = (ull)212370440130137957ll;
const ull base = 131;
char s[100001];
ull a[100001];
ull has(char *s) {
  ull ans = 0;
  for (int i = 0; s[i] != '\\0'; i++)
    ans = (ans * base + (ull)s[i]) % mod;
  return ans;
}
int main() {
  int n;
  scanf("%d", &n);
  int ans = 1;
  for (int i = 1; i <= n; i++) {
    char s[100001] = {0};
    scanf("%s", s), a[i] = has(s);
  }
  sort(a + 1, a + n + 1);
  for (int i = 2; i <= n; i++)
    if (a[i] - a[i - 1])
      ans++;
  printf("%d\\n", ans);
  return 0;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n;
  cin >> n;
  set<string> sset;
  int j;
  int count = 0;

  rep(i, n) {
    string s;
    cin >> s;
    if (!(sset.count(s))) {
      sset.insert(s);
      count++;
    }
  }

  cout << count;

  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int n;
  cin >> n;
  vector<string> sarray;
  int j;
  int count = 1;

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

  rep(i, n) {
    cin >> s;
    j = 0;
    while (j < count && s != sarray.at(j)) {
      j++;
    }
    if (count == j) {
      sarray.push_back(s);
      count++;
    }
  }

  cout << count;

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

#include <algorithm>
#include <iostream>
#include <vector>
#define REP(i, n) for ((i) = 0; (i) < (int)(n); (i)++)
#define ll long long
using namespace std;

int i, j, k;
const ll MOD = 1000000000 + 7;

int main() {
  int n;
  cin >> n;
  vector<string> s;
  int ans = 0;
  j = 0;
  REP(i, n) {
    string tmp;
    cin >> tmp;
    s.push_back(tmp);
  }
  sort(s.begin(), s.end());
  string asahi = "";
  for (auto it = s.begin(); it != s.end(); ++it) {
    if (*it != asahi) {
      ans++;
      asahi = *it;
    }
  }
  cout << ans << '\\n';

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>
#define REP(i, n) for ((i) = 0; (i) < (int)(n); (i)++)
#define ll long long
using namespace std;

int i, j, k;
const ll MOD = 1000000000 + 7;

int main() {
  int n;
  cin >> n;
  vector<string> s;
  int ans = 0;
  j = 0;
  REP(i, n) {
    string tmp;
    bool flg = false;
    cin >> tmp;
    for (auto it = s.begin(); it != s.end(); ++it) {
      if (*it == tmp) {
        flg = true;
        break;
      }
    }
    if (!flg) {
      ans++;
      s.push_back(tmp);
    }
  }

  cout << ans << '\\n';

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

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

int count = 1;
int int_sort(const void *a, const void *b) {
  if (strcmp((char *)a, (char *)b) != 0) {
  }
  return strcmp((char *)a, (char *)b);
}

int main() {
  int N;
  scanf("%d", &N);
  char S[N][11];

  for (int i = 0; i < N; ++i) {
    scanf("%s", S[i]);
  }
  qsort(S, sizeof(S) / sizeof(S[0]), sizeof(S[0]), int_sort);

  for (int i = 1; i < N; i++) {
    if (strcmp(S[i - 1], S[i]) == 0) {

    } else {
      count++;
    }
  }

  printf("%d", count);
}


Error: WA

Fixed submission:

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

int main() {
  int N;
  scanf("%d", &N);
  char S[N][10];
  char tmp[10];
  int count = 1;
  for (int i = 0; i < N; ++i) {
    scanf("%s", S[i]);
  }
  for (int i = 1; i < N; i++) {
    for (int j = 1; j < N; j++) {
      if (strcmp(S[j - 1], S[j]) > 0) {
        strcpy(tmp, S[j - 1]);
        strcpy(S[j - 1], S[j]);
        strcpy(S[j], tmp);
      }
    }
  }
  for (int i = 1; i < N; i++) {
    if (strcmp(S[i - 1], S[i]) == 0) {

    } else {
      count++;
    }
  }
  printf("%d", count);
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n;
  string s[100000];
  std::unordered_map<std::string, int> um;
  int sum = 0;

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

    if (um[name] > 0) {
      // um[name] += 1;
    } else {
      um[name] = 1;
      ++sum;
    }
  }

  cout << sum << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  int n;
  string s[100000];
  int sum = 0;

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

    int exists = 0;
    for (int j = 0; j < sum; ++j) {
      if (s[j] != name)
        continue;

      exists = 1;
      break;
    }

    if (exists == 0) {
      s[sum] = name;
      ++sum;
    }
  }

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

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

int main() {
  int N;
  cin >> N;
  std::map<string, int> m;
  string value;
  for (int i = 0; i < N; i++) {
    cin >> value;
    m[value] = 1;
  }
  cout << m.size() << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  int N;
  cin >> N;
  string value;
  vector<string> vect(0);
  for (int i = 0; i < N; i++) {
    cin >> value;
    bool flag = false;
    for (int j = 0; j < vect.size(); j++) {
      if (value == vect.at(j)) {
        flag = true;
        continue;
      }
    }
    if (!flag) {
      vect.push_back(value);
    }
  }
  cout << vect.size() << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#include "bits/stdc++.h"

using namespace std;

#define ll long long

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

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

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

  for (i = 0; i < a.size(); i++) {
    if (a[i] == a[i + 1])
      n--;
  }

  cout << n;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>

#define ll long long
using namespace std;

int main() {
  ll n;
  ll i, j;
  int len1, len2;
  ll stk;
  int c = 1;
  int count = 0;
  string k;
  string s[200010];

  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> s[i];
    count++;
  }

  for (i = 1; i < n; i++) {
    for (j = n; j > i; j--) {
      len1 = s[j].length();
      len2 = s[j - 1].length();
      if (len1 < len2 || (len1 == len2 && s[j].compare(s[j - 1]) < 0)) {
        k = s[j];
        s[j] = s[j - 1];
        s[j - 1] = k;
      }
    }
  }
  for (i = 1; i < n; i++) {
    if (s[i] == s[i + 1])
      count--;
  }

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

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

int main() {
  int n;
  cin >> n;
  string tmp;
  unordered_set<string> s;
  while (n--) {
    cin >> tmp;
    s.insert(tmp);
  }
  cout << s.size() << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string.h>
using namespace std;
int main(void) {
  int N, match = 0, index = 0;
  char array[1000000][10] = {'\\0'};
  long long ans = 0;

  cin >> N;

  for (int i = 0; i < N; i++) {
    cin >> array[index];
    match = 0;

    for (int j = 0; j < index; j++) {
      if (!strcmp(array[index], array[j])) {
        match = 1;
        break;
        // cout << array[index]<< array[j]<<!strcmp(array[index],array[j])<<' ';
      }
    }
    if (match != 1) {
      ans = ans + 1;
      // cout << ans <<endl;
    }
    index++;
  }
  cout << ans << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <set>
#include <string>
using namespace std;
int main() {
  set<string> s1;
  int n, ans = 0;
  string s;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s;
    if (s1.find(s) == s1.end()) {
      s1.insert(s);
      ans++;
    }
  }
  cout << ans;
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;
string s[200010];
int main() {
  int n, ans = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    int x = 0;
    for (int j = 0; j < i; j++) {
      if (s[i] == s[j])
        x += 1;
    }
    if (x == 0)
      ans += 1;
  }
  cout << ans;
  return 0;
}
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> sina(n);
  int i;
  for (i = 0; i < n; i++)
    cin >> sina[i];
  vector<string> ans;
  set<string> s;
  for (i = 0; i < n; i++) {
    s.insert(sina[i]);
  }
  cout << s.size() << endl;

  return 0;
}


Error: TLE

Fixed submission:

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

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

  vector<string> sina(n);
  int i, j;
  for (i = 0; i < n; i++)
    cin >> sina[i];
  vector<string> ans;
  sort(sina.begin(), sina.end());
  int x, y;
  y = 0;
  for (i = 0; i < n; i++) {
    x = 0;
    for (j = 0; j < y; j++) {
      if (sina[i] == ans[j]) {
        x = 1;
        break;
      }
    }
    if (x == 0) {
      ans.emplace_back(sina[i]);
      y++;
    }
  }
  cout << y << endl;

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

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

using namespace std;

int main(void) {
  int a;
  set<string> st;

  cin >> a;

  for (int i = 0; i < a; i++) {
    string str;
    cin >> str;
    st.insert(str);
  }

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

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;

int main(void) {
  int a;
  vector<string> str;

  cin >> a;
  for (int i = 0; i < a; i++) {
    string str1;
    cin >> str1;

    str.push_back(str1);
  }

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

  cout << str.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> s(n);
  for (int i = 0; i < n; i++) {
    cin >> s.at(i);
  }
  sort(s.begin(), s.end());
  int countt = 1;
  for (int i = 1; i < s.size(); i++) {
    if (s.at(i) != s.at(i - 1)) {
      countt++;
    }
  }

  cout << countt << 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);
  }

  vector<string> a;
  for (int i = 0; i < n; i++) {
    if (a.empty()) {
      a.push_back(s.at(i));
    }
    bool flag = true;
    for (int j = 0; j < a.size(); j++) {
      if (s.at(i) == a.at(j)) {
        flag = false;
      }
    }
    if (flag) {
      a.push_back(s.at(i));
    }
  }

  int ans = a.size();
  cout << ans;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <stdlib.h>
#include <string>
#include <vector>

#define PI 3.14159265358979
#define MOD 1000000007

using namespace std;

int main(void) {
  long long int n, sum;
  map<string, double> s;
  string t;
  int i, j, k;
  bool flag = false;
  cin >> n;
  sum = 0;
  for (i = 0; i < n; i++) {
    cin >> t;
    if (s[t] == 0)
      sum++;
    s[t]++;
  }

  cout << sum << endl;
  /*if(flag)cout << "Yes" << endl;
          else cout << "No" << endl;*/
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <stdlib.h>
#include <string>
#include <vector>

#define PI 3.14159265358979
#define MOD 1000000007

using namespace std;

int main(void) {
  long long int n, sum;
  vector<string> s;
  string t;
  int i, j, k;
  bool flag = false;
  cin >> n;
  sum = 0;
  cin >> t;
  s.push_back(t);
  sum++;
  for (i = 0; i < n - 1; i++) {
    cin >> t;
    j = lower_bound(s.begin(), s.end(), t) - s.begin();
    if (s[j] == t)
      flag = true;
    if (flag == true)
      flag = false;
    else {
      s.push_back(t);
      sum++;
      sort(s.begin(), s.end());
    }
  }
  cout << sum << endl;
  /*if(flag)cout << "Yes" << endl;
          else cout << "No" << endl;*/
  return 0;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  ll n;
  cin >> n;
  vector<string> s(n);
  for (int i = 0; i < n; i++) {
    cin >> s.at(i);
  }

  int ans = n;
  sort(s.begin(), s.end());
  for (int i = 0; i < n - 1; i++) {
    if (s.at(i) == s.at(i + 1)) {
      ans--;
    }
  }

  cout << ans << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  ll n;
  cin >> n;
  vector<string> s(n);
  for (int i = 0; i < n; i++) {
    cin >> s.at(i);
  }

  vector<string> ans = {s.at(0)};
  for (int i = 1; i < n; i++) {
    int count = 0;
    for (int j = 0; j < ans.size(); j++) {
      if (s.at(i) == ans.at(j)) {
        break;
      } else {
        count++;
      }
      if (count == ans.size()) {
        ans.push_back(s.at(i));
      }
    }
  }
  cout << ans.size() << endl;
}
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() {
  int n = 0;
  cin >> n;
  map<string, int> s;
  rep(i, n) {
    string temp;
    cin >> temp;
    s[temp];
  }
  cout << s.size() << 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() {
  int n = 0, result = 0;
  cin >> n;
  vector<string> s(0);
  rep(i, n) {
    string temp;
    cin >> temp;
    if (i == 0)
      s.emplace_back(temp);
    rep(j, s.size()) {
      if (temp == s.at(j)) {
        temp = "aaaaaaaaaaa";
        break;
      }
    }
    if (temp != "aaaaaaaaaaa")
      s.emplace_back(temp);
  }
  cout << s.size() << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#include <map>
using namespace std;
#define ALL(obj) obj.begin(), obj.end()
#define pb(obj) push_back(obj)
#define REP(i, N) for (int i = 0; i < N; i++)
typedef long long ll;
ll const MOD = 1e9 + 7;
using ll = long long;

int main() {
  int n;
  cin >> n;
  map<string, int> data;
  string buf;
  REP(i, n) {
    cin >> buf;
    data[buf] = 0;
  }
  cout << data.size() << 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 = 1;
  for (int i = 1; i < n; i++) {
    bool ans = true;
    for (int j = 1; j <= i - 1; j++) {
      if (data.at(i) == data.at(j)) {
        ans = false;
        break;
      }
    }
    if (!(data.at(0) == data.at(i)) && ans) {
      count++;
    }
  }
  cout << count << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, i;
  cin >> n;
  set<string> st;
  for (i = 0; i < n; i++) {
    string s;
    cin >> s;
    st.insert(s);
  }
  cout << st.size();
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, cnt = 1;
  cin >> n;
  string words[n], value;
  cin >> words[0];
  for (long long int i = 1; i < n; i++) {
    cin >> value;
    for (long long int j = 0; j < i; j++)
      if (value == words[j]) {
        i -= 1;
        n -= 1;
        break;
      } else {
        if (j == i - 1) {
          words[i] = value;
          cnt++;
        }
      }
  }
  cout << cnt << endl;
  return 0;
}