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

#include <algorithm>
#include <cstring>
#include <iostream>
#include <numeric>
#include <set>
#include <vector>

using namespace std;

int main(int argc, char const *argv[]) {
  int N;
  cin >> N;
  string S;
  set<string> gacha;
  for (int i = 0; i < N; i++) {
    cin >> S;
    gacha.insert(S);
  }
  cout << gacha.size();
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cstring>
#include <iostream>
#include <numeric>
#include <vector>

using namespace std;

int main(int argc, char const *argv[]) {
  int N;
  string S;
  cin >> N;
  vector<string> shouhin;
  int cnt = 0;
  for (int i = 0; i < N; i++) {
    cin >> S;
    if (i == 0) {
      shouhin.push_back(S);
    }
    int j;
    for (j = 0; j < shouhin.size(); j++) {
      if (shouhin[j] == S) {
        break;
      }
    }
    if (j == shouhin.size()) {
      shouhin.push_back(S);
    }
  }
  cout << shouhin.size();

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

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

using namespace std;

long long inp_c, i1, out_n;

string inp_a[200005];

long long readNumber() {
  long long temp_func;
  scanf("%lld", &temp_func);
  return temp_func;
};
long long printNumber(long long temp_func) {
  printf("%lld", temp_func);
  return 0;
};

int main() {

  inp_c = readNumber();

  for (i1 = 1; i1 <= inp_c; i1++) {

    cin >> inp_a[i1];
  };

  sort(inp_a + 1, inp_a + 1 + inp_c);

  for (i1 = 1; i1 <= inp_c; i1++) {

    out_n += inp_a[i1] != inp_a[i1 - 1];
  };

  printNumber(out_n);
}

Error: WA

Fixed submission:

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

using namespace std;

long long inp_c, i1, out_n;

string inp_a[100005];

long long readNumber() {
  long long temp_func;
  scanf("%lld", &temp_func);
  return temp_func;
};
long long printNumber(long long temp_func) {
  printf("%lld", temp_func);
  return 0;
};

int main() {

  inp_c = readNumber();

  for (i1 = 1; i1 <= inp_c; i1++) {

    cin >> inp_a[i1];
  };

  sort(inp_a + 1, inp_a + 1 + inp_c);

  for (i1 = 1; i1 <= inp_c; i1++) {

    out_n += inp_a[i1] != inp_a[i1 - 1];
  };

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

// C - gacha
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using ull = unsigned long long;

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

Error: TLE

Fixed submission:

// C - gacha
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using ull = unsigned long long;

int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  rep(i, n) cin >> s[i];
  int ans = 1;
  bool ok = false;
  rep(i, n - 1) {
    for (int j = i + 1; j < n; j++) {
      if (s[i] != s[j])
        ok = true;
      else
        ok = false;
    }
    if (ok)
      ans++;
  }
  cout << ans << endl;
  return 0;
}
Problem p02701 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int i, n;
  cin >> n;
  for (i = 0; i < n; i++) {
    string str;
    cin >> str;
    st.insert(str);
  }
  cout << st.size() << endl;
  return 0;
}


Error: 0

Fixed submission:

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

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


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, c = 0, n, j, p = 0;
  cin >> n;
  string a[n + 2];
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }

  for (i = 0; i + 1 < n; i++) {
    for (j = i + 1; j < n; j++) { // cout<<a[i]<<" "<<a[j]<<endl;
      if (a[i] == a[j]) {
        c++;
      }
    }
    if (c == n - 1) {
      p = 1;
      break;
    }
  }
  p = n - c;
  cout << p << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

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

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  vector<string> v;
  cin >> n;
  for (long long i = 0; i < n; i++) {
    string s;
    cin >> s;
    int flag = 0;
    for (long long j = 0; j < v.size(); j++) {
      if (s == v[j])
        flag = 1;
    }
    if (!(flag))
      v.push_back(s);
  }
  cout << v.size() << endl;
  return 0;
}
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> S(N);
  for (int i = 0; i < N; i++)
    cin >> S.at(i);
  sort(S.begin(), S.end());
  int count = 0;
  for (int i = 0; i < N - 1; i++) {
    if (S.at(i) == S.at(i + 1))
      count++;
  }
  cout << (N - count) << endl;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int N;
  string S[200000];
  cin >> N;
  cin >> S[0];
  string s;
  int count = 1;
  for (int i = 1; i < N; i++) {
    cin >> s;
    for (int j = 0; j < count; j++) {
      if (s == S[j])
        break;
      else if (j == count - 1) {
        S[count] = s;
        count++;
        break;
      }
    }
  }
  cout << count << endl;

  return 0;
}
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;
  string s;
  set<string> myset;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s;
    myset.insert(s);
  }
  cout << myset.size() << endl;
  return 0;
}

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;
  string a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int cur = 1;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (i == 0) {
        if (a[i] != a[j]) {
          cur++;
        }
      } else if (cur > 1) {
        if (a[i] == a[j]) {
          cur = cur - 1;
        }
      }
    }
  }
  cout << cur << 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];
  sort(s.begin(), s.end());
  s.erase(unique(s.begin(), s.end()), s.end());
  int sz;
  sz = s.size();
  cout << sz << endl;
}

Error: TLE

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

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

  if (n - c > 0)
    cout << n - c << endl;
  else
    cout << 1 << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<string> s(n);

  int cnt = n;
  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)) {
      cnt--;
    }
  }
  cout << cnt << endl;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<string> s(n);

  int cnt = n;
  for (int i = 0; i < n; i++) {
    cin >> s.at(i);
    for (int j = 0; j < i; j++) {
      if (s.at(i) == s.at(j)) {
        cnt = cnt - 1;
        break;
      }
      // cout << s.at(i) << "," << s.at(j) << endl;
    }
  }

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

#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
string s[200005];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> s[i];
  }
  sort(s + 1, s + 1 + n);
  int cnt = 1;
  for (int i = 2; i <= n; i++) {
    if (s[i] != s[i - 1]) {
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
string s[10005];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> s[i];
  }
  sort(s + 1, s + 1 + n);
  int cnt = 1;
  for (int i = 2; i <= n; i++) {
    if (s[i] != s[i - 1]) {
      cnt++;
    }
  }
  cout << cnt << 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++) // 普通のループ
#define repr(i, n) for (int i = n; i >= 0; i--) // 逆ループ

// 型名省略
typedef long long ll;
// 値
static const ll MX = 100005;
static const ll MX_ll = 1e18;
const double PI = acos(-1); // π

using namespace std;

// ソート
#define SIZE_OF_ARRAY(array) (sizeof(array) / sizeof(array[0]))

// #include "./lib/generic/search.h"

// 文字列入力した小数値を小数点なくして返す
int changeDoubleToInt(string decimal) {
  decimal.erase(1, 1);                   // 小数点削除
  int n_decimal = atoi(decimal.c_str()); // c_strでchar*に変換後、atoiでintに変換
  return n_decimal;
}

int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  int ans = 0;
  rep(i, n) { cin >> s[i]; }
  sort(s.begin(), s.end()); // vector
  // rep(i, n) cout << s[i] << endl;

  rep(i, n) {
    ans++;
    while (1) {
      if (s[i] == s[i + 1])
        i++;
      else
        break;
    }
  }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h> //全てのヘッダファイルをインクルード

// ループ
#define rep(i, n) for (int i = 0; i < (n); i++) // 普通のループ
#define repr(i, n) for (int i = n; i >= 0; i--) // 逆ループ

// 型名省略
typedef long long ll;
// 値
static const ll MX = 100005;
static const ll MX_ll = 1e18;
const double PI = acos(-1); // π

using namespace std;

// ソート
#define SIZE_OF_ARRAY(array) (sizeof(array) / sizeof(array[0]))

// #include "./lib/generic/search.h"

// 文字列入力した小数値を小数点なくして返す
int changeDoubleToInt(string decimal) {
  decimal.erase(1, 1);                   // 小数点削除
  int n_decimal = atoi(decimal.c_str()); // c_strでchar*に変換後、atoiでintに変換
  return n_decimal;
}

int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  vector<int> ans(n);
  int n_ans = 0;
  rep(i, n) {
    cin >> s[i];
    ans[i] = 0;
  }
  rep(i, n) {
    if (ans[i] == 0) {
      ans[i] = 1;
      n_ans++;
      rep(j, n) {
        if (ans[j] == 0) {
          if (s[i] == s[j])
            ans[j] = 1;
        }
      }
    }
  }
  cout << n_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 (int i = 0; i < (n); ++i)
#define REP(i, d, n) for (int i = (d); i < (n); ++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main() {

  ll n;
  cin >> n;
  ll ans = n;
  ll ka = 0;
  vector<string> a(n);
  rep(i, n) { cin >> a.at(i); }

  sort(all(a));
  rep(i, n - 1) {
    if (a.at(i) == a.at(i + 1))
      ka++;
  }

  cout << ans - ka << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define REP(i, d, n) for (int i = (d); i < (n); ++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main() {

  ll n;
  cin >> n;
  ll ans = n;
  ll ka = 0;
  vector<string> a(n);
  rep(i, n) {
    cin >> a.at(i);
    rep(j, i) {
      if (a.at(i) == a.at(j)) {
        ka++;
        break;
      }
    }
  }

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

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define REP(i, d, n) for (int i = (d); i < (n); ++i)
#define all(v) v.begin(), v.end()
using ll = long long;
int main() { // 言語変えろ言語変えろ言語変えろ言語変えろ言語変えろ

  int n;
  cin >> n;
  vector<string> a(n);

  int ans = 1;

  rep(i, n) { cin >> a.at(i); }
  sort(all(a));

  rep(j, n - 1) {
    if (a.at(j) != a.at(j + 1)) {
      ans++;
    }
  }

  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define REP(i, d, n) for (int i = (d); i < (n); ++i)
#define all(v) v.begin(), v.end()
using ll = long long;
int main() { // 言語変えろ言語変えろ言語変えろ言語変えろ言語変えろ

  int n;
  cin >> n;
  vector<string> a(n);
  int minus = 0;

  rep(i, n) {
    cin >> a.at(i);

    rep(j, i) {
      if (a.at(i) == a.at(j)) {
        minus++;
        break;
      }
    }
  }
  cout << n - minus << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int N, ans = 0;
  cin >> N;
  vector<string> V(N);
  for (int i = 0; i < N; i++)
    cin >> V.at(i);
  sort(V.begin(), V.end());
  V.erase(unique(V.begin(), V.end()), V.end());
  cout << V.size() << endl;
}


Error: TLE

Fixed submission:

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

int main() {
  int N, ans = 0;
  cin >> N;
  vector<string> V(N);
  for (int i = 0; i < N; i++) {
    cin >> V.at(i);
    bool A = true;
    for (int j = 0; j < i; j++) {
      if (V.at(i) == V.at(j)) {
        A = false;
        break;
      }
    }
    if (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, i = 0, j = 1, cnt = 1;

  cin >> n;
  vector<string> s(n);

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

  while (i < n - 1 && j < n) {
    if (s.at(j) == s.at(i)) {
      j++;
    } else {
      i = j;
      j = i + 1;
      cnt++;
    }
  }
  cout << cnt << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, cnt = 0;
  bool flag;

  cin >> n;
  vector<string> s(n);

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

#include <iostream>
using namespace std;
#include <set>
#include <string>
int main() {
  int n;
  set<string, greater<string>> str1;
  string str;
  cin >> n;
  while (n--) {
    cin >> str;
    str1.insert(str);
  }
  cout << str1.size() << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
#include <string>
#include <vector>
int main() {
  int n, count = 0, flag = 0;
  string str;
  cin >> n;
  vector<string> str1(n);
  while (n--) {
    cin >> str;
    for (string c : str1) {
      if (c == str) {
        flag = 1;
        break;
      }
    }
    if (!flag || str1.size() == 0) {
      str1.push_back(str);
      count++;
    }
  }
  cout << count << endl;
  return 0;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

#define deg_to_rad(deg) (((deg) / 360) * 2 * M_PI)
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)

typedef long long ll;
typedef long double ld;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<string> vs;

typedef vector<vector<int>> vvi;
typedef vector<vector<ld>> vvd;
typedef vector<vector<ll>> vvl;

typedef vector<vector<vector<int>>> vvvi;
typedef vector<vector<vector<ld>>> vvvd;
typedef vector<vector<vector<ll>>> vvvl;

constexpr int MOD = 1000000007;
constexpr char nl = '\\n';

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << fixed << setprecision(15);

  int N;
  cin >> N;
  map<string, int> S;

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

  cout << S.size() << nl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define deg_to_rad(deg) (((deg) / 360) * 2 * M_PI)
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)

typedef long long ll;
typedef long double ld;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<string> vs;

typedef vector<vector<int>> vvi;
typedef vector<vector<ld>> vvd;
typedef vector<vector<ll>> vvl;

typedef vector<vector<vector<int>>> vvvi;
typedef vector<vector<vector<ld>>> vvvd;
typedef vector<vector<vector<ll>>> vvvl;

constexpr int MOD = 1000000007;
constexpr char nl = '\\n';

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << fixed << setprecision(15);

  int N;
  cin >> N;
  vs S;

  for (int i = 0; i < N; i++) {
    string s;
    cin >> s;
    if (i == 0) {
      S.push_back(s);
    } else {
      auto result = find(S.begin(), S.end(), s);
      if (result == S.end()) {
        S.push_back(s);
      }
    }
  }

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

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

int main() {
  int n;
  cin >> n;
  string s[n];
  // map<Keyの型, Valueの型> 変数名;
  map<string, int> ans;
  int count = 0;
  for (int i = 0; i < n; i++) {
    string x;
    cin >> s[i];
    x = s[i];
    if (ans[x] != 1) {
      ans[x] = 1;
      count += 1;
    }
  }
  // cout << ans[0] <<endl;
  cout << count << endl;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  long long n;
  cin >> n;
  string s[n];
  string ans[n];
  long long count = 0;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    int x = 0;
    for (int j = 0; j < count; j++) {
      if (s[i] == ans[j]) {
        x = 1;
      }
    }
    if (x == 0 && s[i] != "") {
      ans[count] = s[i];
      count += 1;
    }
  }
  // cout << ans[0] <<endl;
  cout << count << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int i, j, n;
  int flag = 0;
  int count = 0;

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

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

  for (i = 0; i < s.size(); i++) {
    count++;
  }

  cout << count << endl;
}


Error: TLE

Fixed submission:

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

int main() {
  int i, j, n;
  int flag = 0;
  int count = 0;

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

  for (i = 0; i < n; i++) {
    flag = 0;
    for (j = 0; j < i; j++) {
      if (s.at(i) == s.at(j)) {
        flag = 1;
      }
    }
    if (flag == 0) {
      count++;
    }
  }

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

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

int main() {
  int N;
  string a;
  vector<string> s;

  cin >> N;

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

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

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

Error: TLE

Fixed submission:

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

int main() {
  int N;
  string a;
  vector<string> v;
  vector<string>::iterator itr = v.begin();

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

    itr = std::find(v.begin(), v.end(), a);
    if (itr == v.end()) {
      v.push_back(a);
    }
  }

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

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

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

int main() {
  int n, ans = 0;
  cin >> n;
  map<string, int> s;
  string word;
  for (int i = 0; i < n; i++) {
    cin >> word;
    if (s.count(word))
      continue;
    else {
      s[word] = 1;
      ans++;
    }
  }

  cout << ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

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

const int MAX = 105;

int main() {
  int n, ans = 0;
  cin >> n;
  vector<string> s(n);
  string word;
  for (int i = 0; i < n; i++) {
    cin >> word;
    if (find(s.begin(), s.end(), word) != s.end())
      continue;
    else {
      s.push_back(word);
      ans++;
    }
  }

  cout << ans << endl;

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

#include <algorithm>
#include <cmath>
#include <iostream>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define PI (acos(-1))

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

  set<string> S;
  string a;
  for (int i = 0; i < N; i++) {
    cin >> a;
    S.insert(a);
  }

  cout << S.size();
}


Error: TLE

Fixed submission:

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

int main() {

  int N;
  cin >> N;

  vector<string> v(N);

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

  vector<string> w(N);

  w[0] = v[0];
  int count = 1;

  for (int j = 1; j < N; j++) {

    for (int k = 0; k < count; k++) {

      if (w[k] == v[j]) {
        break;
      }

      if (k == count - 1) {
        w[count] = v[j];
        count++;
      }
    }
  }

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

#include <iostream>
#include <set>
using namespace std;
int main() {
  set<string> s;
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    string x;
    cin >> x;
    s.insert(x);
  }

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

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
typedef long long ll;
const int mod = 998244353;
const int maxn = 2e5 + 5;
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
int main() {
  int n;
  string s[maxn];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (s[i].length() != 0)
      for (int j = i + 1; j < n; j++) {
        if (s[i] == s[j]) {
          s[j] = "";
        }
      }
  }
  for (int i = 0; i < n; i++) {
    if (s[i].length() != 0)
      ans++;
  }
  cout << ans << endl;
  return 0;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

// gacha
#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];
  }

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

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

Error: TLE

Fixed submission:

// gacha
#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];
  }
  vector<string> v;
  v.push_back(s[0]);
  for (int i = 1; i < n; i++) {
    v.push_back(s[i]);
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
  }
  cout << v.size() << endl;
  return 0;
}