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

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

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

Error: TLE

Fixed submission:

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

int main() {
  int n, ans;
  cin >> n;
  ans = 1;
  vector<string> item(n);
  for (int i = 0; i < n; i++) {
    cin >> item.at(i);
  }
  for (int i = 1; i < n; i++) {
    int a = 0;
    for (int j = i - 1; j >= 0; j--) {
      if (item.at(i) == item.at(j)) {
        a = 1;
        break;
      }
    }
    if (a == 0)
      ans++;
  }
  cout << ans << 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++)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
typedef long long ll;
long long mod = 1e9 + 7;
const int iINF = 0x3f3f3f3f;
const long long INF = 1LL << 60;
using namespace std;

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;
}

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

  rep(i, n) {
    string str;
    cin >> str;
    sv.push_back(str);
  }
  sort(sv.begin(), sv.end());
  sv.erase(std::unique(sv.begin(), sv.end()), sv.end());
  cout << sv.size() << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
typedef long long ll;
long long mod = 1e9 + 7;
const int iINF = 0x3f3f3f3f;
const long long INF = 1LL << 60;
using namespace std;

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;
}

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

  rep(i, n) {
    string str;
    cin >> str;
    if (find(sv.begin(), sv.end(), str) == sv.end())
      sv.push_back(str);
  }

  cout << sv.size() << 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;
  vector<string> S(N);
  for (int i = 0; i < N; i++) {
    cin >> S[i];
  }
  int M = N;
  sort(S.begin(), S.end());
  for (int i = 0; i < N; i++) {
    if (S[i] == S[i + 1]) {
      M -= 1;
    }
  }
  cout << M << endl;
}

Error: TLE

Fixed submission:

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

#include <algorithm>
#include <iostream>
#include <set>
int main() {
  int N;
  std::string S;
  std::set<std::string> kind;

  std::cin >> N;
  for (int i = 0; i < N; i++) {
    std::cin >> S;
    kind.insert(S);
  }
  std::cout << kind.size() << std::endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
int main() {
  int N;
  std::string S[200000];
  std::vector<std::string> kind;

  std::cin >> N;
  for (int i = 0; i < N; i++) {
    std::cin >> S[i];
    auto check = std::find(kind.begin(), kind.end(), S[i]);
    if (check == kind.end())
      kind.push_back(S[i]);
  }
  std::cout << kind.size() << std::endl;

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

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

using namespace std;

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

  vector<string> s;
  string temp;
  int ans = 0;

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

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

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

  cout << n - ans;

  return 0;
}

Error: TLE

Fixed submission:

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

using namespace std;

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

  vector<string> s;
  string temp;
  int ans = 0;
  bool is;

  for (int i = 0; i < n; i++) {
    is = false;
    cin >> temp;
    for (int j = 0; j < ans; j++) {
      if (temp[0] != s[j][0]) {
        continue;
      }
      if (temp == s[j]) {
        is = true;
        break;
      }
    }
    if (is != true) {
      s.push_back(temp);
      ans++;
    }
  }

  cout << ans;

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

#include <algorithm>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <cmath>
#include <math.h>

#define rep(i, m, n) for (int i = (m); i < (n); ++i)
#define rem(i, m, n) for (int i = (m); i > (n); --i)
#define MOD 1000000007

using namespace std;

using ll = long long int;
using std::swap;

vector<long long int> v;
vector<long long int> w;

int main() {
  vector<string> S;
  int n, ans = 0;
  string st;

  cin >> n;
  S.resize(n);
  rep(i, 0, n) { cin >> S[i]; }
  sort(S.begin(), S.end());
  rep(i, 0, n - 1) {
    if (S[i] == S[i + 1])
      ++ans;
  }
  cout << S.size() - ans << '\\n';

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <cmath>
#include <math.h>

#define rep(i, m, n) for (int i = (m); i < (n); ++i)
#define rem(i, m, n) for (int i = (m); i > (n); --i)
#define MOD 1000000007

using namespace std;

using ll = long long int;
using std::swap;

vector<long long int> v;
vector<long long int> w;

int main() {
  vector<string> S;
  int n, ans;
  string st;

  cin >> n;
  rep(i, 0, n) {
    cin >> st;
    int x = 1;
    rep(j, 0, S.size()) {
      if (st == S[j]) {
        x = 0;
        break;
      }
    }
    if (x == 1)
      S.push_back(st);
  }
  cout << S.size() << '\\n';

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

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

using namespace std;

int main(int argc, char *argv[]) {
  int n, i;
  cin >> n;
  vector<string> gacha(n);
  string target;
  int count = 0;

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

  sort(gacha.begin(), gacha.end());
  gacha.erase(unique(gacha.begin(), gacha.end()), gacha.end());

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

  return 0;
}

Error: TLE

Fixed submission:

#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main(int argc, char *argv[]) {
  int n, i;
  cin >> n;
  vector<string> gacha(n);
  string target;
  int count = 0;

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

  do {
    target = gacha[0];
    for (i = gacha.size() - 1; i >= 0; i--) {
      if (gacha[i] == target)
        gacha.erase(gacha.begin() + i);
    }
    count++;
  } while (gacha.size() > 0);

  cout << count << endl;

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

#include <bits/stdc++.h>
using namespace std;
map<string, bool> h;
int main() {
  int n;
  cin >> n;
  int ans = 0;
  string a;
  while (n--) {
    cin >> a;
    if (!h[a]) {
      h[a] = 1;
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
#define b 197
using namespace std;
typedef unsigned long long ull;
ull a[10010], k;
char c[10010];
int n, s = 1;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    k = 0;
    scanf("%s", c);
    int l = strlen(c);
    for (int j = 0; j < l; j++)
      k = k * b + c[j];
    a[i] = k;
  }
  sort(a, a + n);
  for (int i = 1; i < n; i++)
    if (a[i] ^ a[i - 1])
      s++;
  printf("%d", s);
  return 0;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  long long 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 = 1; i < N; i++) {
    if (S[i] != S[i - 1])
      count++;
  }

  cout << count << endl;
}


Error: TLE

Fixed submission:

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

int main() {
  long long N, count = 1;
  cin >> N;
  vector<string> S(N);
  for (int i = 0; i < N; i++) {
    cin >> S[i];
    if (i > 0) {
      int r = 1;
      for (int j = 0; j < i; j++) {
        if (S[j] == S[i])
          r = 0;
      }
      count += r;
    }
  }
  cout << count << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <map>
using namespace std;
int main() {
  int n;
  cin >> n;
  int counter = 0;
  string x;
  // string y[];
  map<string, int> y;
  for (int i = 0; i < n; i++) {
    cin >> x;
    y[x];
  }
  // counter=y.size();
  cout << y.size() << endl;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int n;
  cin >> n;
  int counter = 0;
  string x[n];
  for (int i = 0; i < n; i++) {
    cin >> x[i];
    int u = 0;
    for (int j = 0; j < i; j++) {
      if (x[i] == x[j]) {
        u++;
      }
    }
    if (u == 0) {
      counter++;
    }
  }
  cout << counter << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using namespace std;

int main() {
  int N;
  cin >> N;
  vector<string> S(N);
  map<string, bool> M;
  int kind = 0;
  for (int i = 0; i < N; i++) {
    cin >> S[i];
    if (M[S[i]])
      continue;
    else {
      M[S[i]] = true;
      kind++;
    }
  }
  cout << kind << 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> S(N);
  int kind = 0;
  for (int i = 0; i < N; i++) {
    cin >> S[i];
    bool identity = true;
    for (int j = 0; j < i; j++) {
      if (S[i] == S[j]) {
        identity = false;
        break;
      }
    }
    if (identity)
      kind++;
  }
  cout << kind << endl;
  return 0;
}
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 P = pair<int, int>;
using ll = long long;

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

  rep(i, n) {
    string key = s[i];
    ans[key] = 1;
  }

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

Error: TLE

Fixed submission:

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

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

  vector<string> ans;
  rep(i, n) {
    bool thing = false;
    rep(j, ans.size()) {
      if (s[i] == ans[j]) {
        thing = true;
        break;
      }
    }
    if (thing)
      continue;
    ans.push_back(s[i]);
  }

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

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
  int i, j = 0, b = 1;
  cin >> i;
  vector<string> S(i);
  for (j = 0; j < i; j++) {
    cin >> S.at(j);
  }
  sort(S.begin(), S.end());
  for (j = 0; j < (i - 1); j++) {
    if (S.at(j) != S.at(j + 1)) {
      b++;
    }
  }
  cout << b;
}

Error: WA

Fixed submission:

#include <iostream>
#include <string>
using namespace std;
int main() {
  string keihin[10000];
  string buffer;
  int i, j = 0, k = 0, b = 0;
  bool a = true;
  cin >> i;
  for (j = 0; j < i; j++) {
    cin >> buffer;
    for (k = 0; k < j; k++) {
      if (buffer == keihin[k])
        a = false;
    }
    if (a) {
      keihin[k] = buffer;
      b++;
    }
    a = true;
  }
  cout << b;
  return 0;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

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

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  int ans = 0;
  bool flag = true;
  for (int i = 0; i < n; i++) {
    string a;
    cin >> a;
    for (auto S : s) {
      if (S == a) {
        flag = false;
        break;
      }
    }
    if (flag) {
      s[i] = a;
      ans++;
    }
  }
  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;
  set<string> S;
  string l;
  for (int i = 0; i < N; i++) {
    cin >> l;
    S.insert(l);
  }
  cout << S.size() << endl;
}

Error: TLE

Fixed submission:

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

#define SIZE_OF_ARRAY(array) (sizeof(array) / sizeof(array[0]))

int main() {
  int N;
  cin >> N;
  string S[N];
  int count = 0;
  for (int i = 0; i < N; i++) {
    cin >> S[i];
  }
  std::sort(S, S + SIZE_OF_ARRAY(S));
  for (int i = 0; i < N; i++) {
    bool belong = true;
    for (int k = 0; k < i; k++) {
      if (S[i] == S[k]) {
        belong = false;
        break;
      }
    }
    if (belong) {
      count++;
    }
  }
  cout << count;
}
Problem p02701 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
using namespace std;
typedef unsigned long long ull;
const ull mod = (ull)212370440130137957ll;
const ull base = 131;
char s[200001];
ull a[200001];
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;
}

Error: WA

Fixed submission:

#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());
  unique(a.begin(), a.end());
  while (a[cnt] > a[cnt - 1])
    cnt++;
  cout << cnt;
  return 0;
}
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 c = 0;
  string get;
  for (int i = 0; i < n; i++) {
    if (s.at(i) != get) {
      c++;
      get = s.at(i);
    }
  }
  cout << c << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  int count = 0;
  string get;
  bool check;
  for (int i = 0; i < n; i++) {
    cin >> get;
    check = true;
    for (int j = 0; j < i; j++) {
      if (get == s.at(j)) {
        check = false;
        break;
      }
    }
    if (check)
      count++;
    s.at(i) = get;
  }
  cout << count << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)
#define Sort(Array) sort(Array.begin(), Array.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define out(ans) cout << ans << endl;

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

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

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

  ll ans = n;
  for (ll i = 1; i < n; i++) {
    if (s[i] == s[i - 1])
      ans--;
  }
  out(ans);
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)
#define Sort(Array) sort(Array.begin(), Array.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define out(ans) cout << ans << endl;

int main() {
  ll n;
  cin >> n;
  vector<string> s;
  ll ans = 0;
  for (ll i = 0; i < n; i++) {
    // printf("%d time\\n", i);
    string k;
    cin >> k;
    if (binary_search(s.begin(), s.end(), k)) { // あったら
      // printf("already exist ");
      // out(k);
      continue;
    } else {
      ans++; // なかったら
      s.push_back(k);
      Sort(s);
    }
  }
  out(ans);
}
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;
  set<string> st;
  rep(i, n) {
    string s;
    cin >> s;
    st.insert(s);
  }
  cout << st.size() << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

typedef long long LL;
typedef long double LD;
const int mod = 1000000007;

int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int n;
  vector<string> s;
  string tmp;
  int tmp1 = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    tmp1 = 0;
    cin >> tmp;
    for (int j = 0; j < tmp.size(); j++) {
      tmp1 += tmp[j];
    }
    sort(s.begin(), s.end());
    bool f = binary_search(s.begin(), s.end(), tmp);
    if (s.size() == 0)
      s.push_back(tmp);
    else if (f)
      ;
    else
      s.push_back(tmp);
  }
  cout << s.size() << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int N;
  int count = 0;
  cin >> N;

  vector<string> data(N);
  vector<string> Gdata(N);

  for (int i = 0; i < N; i++) {
    cin >> data.at(i);
  }

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

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

Error: TLE

Fixed submission:

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

int main() {
  int N;
  int count = 0;
  cin >> N;

  vector<string> data(N);
  vector<string> Gdata(N);

  for (int i = 0; i < N; i++) {
    cin >> data.at(i);
  }

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

    for (int j = 0; j < count; j++) {
      if (data.at(i) == Gdata.at(j)) {
        sameflag = true;
        break;
      }
    }
    if (sameflag)
      continue;
    Gdata.at(count) = data.at(i);
    count++;
  }
  cout << count << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

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

// すべての入力を受け取ってソートし重複していないのを取る
int main() {
  vector<string> v;
  int n, cnt = 1;
  string str;
  int f = 0;
  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> str;
    v.push_back(str);
  }
  sort(v.begin(), v.end());
  for (int i = 0; i < n - 1; i++) {
    if (v[i] != v[i + 1]) {
      cnt++;
    }
  }
  cout << cnt << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  vector<string> v;
  int n;
  string str;
  int f = 0;
  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> str;
    if (i == 0) {
      v.push_back(str);
    } else {
      for (auto itr = v.begin(); itr != v.end(); itr++) {
        if (*itr == str) {
          f = 1;
          break;
        }
      }
      if (f == 0) {
        v.push_back(str);
      }
      f = 0;
    }
  }
  cout << v.size() << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios {
  fast_ios() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  };
} fast_ios_;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end)                                                     \\
  for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end)                                                    \\
  for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
const lint mod = 1e9 + 7;

int main() {
  lint n;
  cin >> n;
  std::vector<string> s(n);
  REP(i, n) cin >> s[i];

  // 辞書順ソート
  sort(ALL(s));
  // 重複を飛ばして数える
  lint cnt = 0;
  REP(i, n - 1) {
    if (s[i] != s[i + 1])
      cnt++;
  }

  cout << cnt + 1 << "\\n";
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios {
  fast_ios() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  };
} fast_ios_;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end)                                                     \\
  for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end)                                                    \\
  for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
const lint mod = 1e9 + 7;

int main() {
  lint n;
  cin >> n;
  string tmp;
  lint cnt = 0;
  std::vector<std::vector<string>> found(10);
  REP(i, n) {
    cin >> tmp;
    auto itr = find(ALL(found[tmp.size() - 1]), tmp);
    if (itr == found[tmp.size() - 1].end()) {
      found[tmp.size() - 1].push_back(tmp);
      cnt++;
    }
  }

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

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

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


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
int main() {
  long long N;
  cin >> N;
  vector<string> S(N);
  for (int i = 0; i < N; i++) {
    cin >> S[i];
  }
  int ans = 0;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (S[i] != S[j]) {
        ans++;
      }
    }
  }
  long long A = N - 1;
  if (ans == 0) {
    cout << 1 << endl;
  } else {
    cout << ans / A << endl;
  }
}
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(0);
  int n;
  cin >> n;
  vector<string> a(n);
  int count = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  a.erase(unique(a.begin(), a.end()), a.end());
  cout << size(a) << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<string> a;
  int count = 0;
  for (int i = 0; i < n; i++) {
    bool t = 1;
    string s;
    cin >> s;
    for (int j = 0; j < count; j++) {
      if (a[j] == s) {
        t = 0;
        continue;
      }
    }
    if (t) {
      a.push_back(s);
      count++;
    }
  }
  cout << count << '\\n';
}