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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll M = 1000000007;
// MOD??
long long mod(long long val, long long m) {
  long long res = val % m;
  if (res < 0)
    res += m;
  return res;
}
ll mpow(ll x, ll n) { // x^n(mod M) ????pow(x,n)?????????????mod??
  ll ans = 1;
  while (n != 0) {
    if (n & 1)
      ans = ans * x % M;
    x = x * x % M;
    n = n >> 1;
  }
  return ans;
}
int main() {
  ll i, n, j, f = 0, c = 0;
  cin >> n;
  map<string, int> s;
  string x;
  for (i = 0; i < n; i++) {
    cin >> x;
    s[x]++;
  }
  cout << s.size() << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll M = 1000000007;
// MOD??
long long mod(long long val, long long m) {
  long long res = val % m;
  if (res < 0)
    res += m;
  return res;
}
ll mpow(ll x, ll n) { // x^n(mod M) ????pow(x,n)?????????????mod??
  ll ans = 1;
  while (n != 0) {
    if (n & 1)
      ans = ans * x % M;
    x = x * x % M;
    n = n >> 1;
  }
  return ans;
}
int main() {
  ll i, n, j, f = 0, c = 0;
  cin >> n;
  vector<string> s(n);
  for (i = 0; i < n; i++) {
    cin >> s[i];
    for (j = i - 1; j >= 0; j--) {
      if (s[i] == s[j]) {
        f++;
      }
    }
    if (f > 0) {
      c--;
      f = 0;
    }
  }
  cout << c + n << endl;
  return 0;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

// マクロ
// forループ関係
// 引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
// Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
// xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end() // sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      // sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))   // 最大値を求める
#define MIN(x) *min_element(ALL(x))   // 最小値を求める
// 定数
#define INF 1000000000000 // 10^12:極めて大きい値,∞
#define MOD 1000000007    // 10^9+7:合同式の法
#define MAXR 100000 // 10^5:配列の最大のrange(素数列挙などで使用)
#define PI 3.14159265359 // πの値
// 略記
#define PB push_back // vectorヘの挿入
#define MP make_pair // pairのコンストラクタ
#define F first      // pairの一つ目の要素
#define S second     // pairの二つ目の要素
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  set<string> data;
  ll N;
  cin >> N;
  string str;
  REP(i, N) {
    cin >> str;
    data.insert(str);
  }
  cout << data.size();
}

Error: TLE

Fixed submission:

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

int main() {
  int N;
  string x, y;
  cin >> N;
  vector<string> data;
  cin >> y;
  data.push_back(y);
  for (int i = 1; i < N; i++) {
    cin >> x;
    bool jajaja = true;
    for (int j = 0; j < data.size(); j++) {
      if (data[j] == x) {
        jajaja = false;
        break;
      }
    }
    if (jajaja) {
      data.push_back(x);
    }
  }
  cout << data.size();
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

  int N;
  cin >> N;
  set<string> S;
  string p;

  rep(i, N) {
    cin >> p;
    S.insert(p);
  }

  cout << S.size() << "\\n";
}


Error: TLE

Fixed submission:

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

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

  int N;
  cin >> N;
  vector<string> S;
  string p;

  rep(i, N) {
    cin >> p;
    bool jud = true;
    rep(j, S.size()) if (S[j] == p) {
      jud = false;
      break;
    }
    if (jud) {
      S.push_back(p);
    }
  }

  cout << S.size() << "\\n";
}
Problem p02701 (C++) — buggy submission, verdict: Runtime Error

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

const int N = 2e5 + 10;
string s[N];

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

Error: 0

Fixed submission:

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

const int N = 1e5 + 10;
string s[N];

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> s[i];
  sort(s, s + n);
  cout << (unique(s, s + n) - s) << endl;
  return 0;
}
Problem p02701 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <string>
using namespace std;
map<string, int> mp;
char s[15];
int main() {
  int n;
  scanf("%d\\n", &n);
  string tmp;
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%s", s);
    // scanf("\\n");
    string tmp = "";
    int ls = strlen(s);
    for (int i = 0; i < ls; i++) {
      tmp += s[i];
    }
    if (mp[tmp] == 0) {
      mp[tmp] = 1;
      ans++;
    }
  }
  printf("%d\\n", ans);
  return 0;
}


Error: 0

Fixed submission:

#include <cstdio>
#include <cstring>
using namespace std;
const unsigned P1 = 1e9 + 7, P2 = 1e9 + 13;
unsigned hash1[10005], hash2[10005];
int main() {
  int ans = 0;
  int n;
  scanf("%d", &n);
  for (int k = 1; k <= n; k++) {
    char s[1505];
    scanf("%s", s);
    int len = strlen(s);
    hash1[k] = 0;
    hash2[k] = 0;
    for (int i = 0; i < len; i++) {
      hash1[k] = hash1[k] * P1 + s[i];
      hash2[k] = hash2[k] * P2 + s[i];
    }
    ans++;
    for (int i = 1; i < k; i++) {
      if (hash1[i] == hash1[k] && hash2[i] == hash2[k]) {
        ans--;
        break;
      }
    }
  }
  printf("%d\\n", ans);
  return 0;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int num;
  cin >> num;
  // 景品の種類が、すでに持っている景品の種類と一致しているかみて、一致していなければインクリメントする

  string temp;
  int ans = 0;

  //    vector<string> list(num+1, "111");

  // map<string, int> list;
  set<string> list;

  // くじ引き1つ1つについて確認
  for (int i = 1; i <= num; i++) {
    cin >> temp;

    if (list.count(temp) == 0) {
      list.insert(temp);
      ans++;
    }
  }

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

Error: TLE

Fixed submission:

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

bool isKaibun(string s);

int main() {
  int num;
  cin >> num;
  // 景品の種類が、すでに持っている景品の種類と一致しているかみて、一致していなければインクリメントする

  string temp;
  int ans = 0;

  vector<string> list(num + 1, "111");

  // くじ引き1つ1つについて確認
  for (int i = 1; i <= num; i++) {
    cin >> temp;

    for (int k = 1; k <= num; k++) {
      if (list[k] == "111") {
        list[k] = temp;
        ans++;
        break;
      }

      if (list[k] == temp) {
        // 重複している
        break;
      }
    }
  }

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

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

#define vint vector<int>
#define vvint vector<vint>
#define rep(i, n) for (int i = 0; i < (int)(n); i++) // 繰り返し処理
#define all(x) (x).begin(), (x).end() // 全体 こんな感じで使う→sort(all(a));
#define ct(a) cout << a << endl
#define iceil(a, b)                                                            \\
  (a + (b - 1)) /                                                              \\
      b // int ceil : 繰り上げの割り算
        // 通常のceilではceil((7.0/2.0))のようにしなければならなかった。
vint CinLine(int N) {
  vint v(N);
  for (int i = 0; i < N; i++) {
    cin >> v.at(i);
  }
  return v;
} // cin line 連続でvectorに格納
void CoutLine(vint v) {
  for (int i = 0; i < v.size() - 1; i++) {
    cout << v.at(i) << " ";
  }
  cout << v.at(v.size() - 1) << endl;
}

template <class T> inline void container_sort(std::vector<T> &v) {
  std::sort(v.begin(), v.end());
}
template <class T> inline void container_sort(std::list<T> &v) { v.sort(); }

//////////////////////////////
// 重複削除関数
template <class T> void vec_unique(T &v) {

  container_sort(v);
  v.erase(std::unique(v.begin(), v.end()), v.end());
}

void Main() {
  int N;
  cin >> N;

  vector<string> S(N);
  rep(i, N) { cin >> S.at(i); }
  vec_unique(S);
  ct(S.size());

#if 0
    vector<string> ans;

    rep(i,N){
        string s;
        cin >> s;
        if(i == 0){
            ans.push_back(s);
        }else{
            bool b = true;
            rep(j,ans.size()){
                if(ans.at(j) == s){
                    b = false;
                    break;
                }
                if(b){
                    ans.push_back(s);
                    break;
                }
            }
        }
    }
    ct(ans.size());
#endif
}

int main() { Main(); }


Error: TLE

Fixed submission:

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

#define vint vector<int>
#define vvint vector<vint>
#define rep(i, n) for (int i = 0; i < (int)(n); i++) // 繰り返し処理
#define all(x) (x).begin(), (x).end() // 全体 こんな感じで使う→sort(all(a));
#define ct(a) cout << a << endl
#define iceil(a, b)                                                            \\
  (a + (b - 1)) /                                                              \\
      b // int ceil : 繰り上げの割り算
        // 通常のceilではceil((7.0/2.0))のようにしなければならなかった。
vint CinLine(int N) {
  vint v(N);
  for (int i = 0; i < N; i++) {
    cin >> v.at(i);
  }
  return v;
} // cin line 連続でvectorに格納
void CoutLine(vint v) {
  for (int i = 0; i < v.size() - 1; i++) {
    cout << v.at(i) << " ";
  }
  cout << v.at(v.size() - 1) << endl;
}
void Main() {
  int N;
  cin >> N;
  /*
  vector<string> S(N);
  rep(i,N){
      cin >> S.at(i);
  }
  */
  vector<string> ans;

  rep(i, N) {
    string s;
    cin >> s;
    if (i == 0) {
      ans.push_back(s);
    } else {
      bool b = true;
      rep(j, ans.size()) {
        if (ans.at(j) == s) {
          b = false;
          break;
        }
      }
      if (b) {
        ans.push_back(s);
      }
    }
  }
  ct(ans.size());
}

int main() { Main(); }
Problem p02701 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int N = 0;
  std::cin >> N;

  if (N == 1) {
    std::cout << "1\\n";
    return 0;
  }

  std::vector<std::string> S(N);
  for (int i = 0; i < N; ++i) {
    std::cin >> S.at(i);
  }

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

  int overcoatNum = 0;
  std::string searchStr = S.at(0);
  for (int i = 1, n = S.size(); i < n; ++i) {
    if (searchStr == S.at(i)) {
      overcoatNum++;
    } else {
      searchStr = S.at(i);
    }
  }

  std::cout << S.size() - overcoatNum << "\\n";

  return 0;
}

Error: 0

Fixed submission:

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

int main() {
  int N = 0;
  std::cin >> N;

  std::vector<std::string> S(N);
  for (int i = 0; i < N; ++i) {
    std::cin >> S.at(i);
  }

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

  for (int i = 0, n = S.size() - 1; i < n; ++i) {
    if (S.at(i) == S.at(i + 1)) {
      S.erase(S.begin() + i);
      i--;
      n = S.size() - 1;
    }
  }
  if (S.at(0) == S.at(1)) {
    S.erase(S.begin() + 1);
  }

  std::cout << S.size() << "\\n";

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

  while (n--) {
    string s;
    cin >> s;
    v.push_back(s);
  }

  unordered_set<string> s;
  int distinct = 0;
  for (int i = 0; i < v.size(); i++) {
    if (s.find(v[i]) == s.end()) {
      s.insert(v[i]);
      distinct++;
    }
  }
  cout << distinct << endl;
}


Error: -11

Fixed submission:

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

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

  vector<string> v;

  while (n--) {
    string s;
    cin >> s;
    v.push_back(s);
  }

  vector<string>::iterator ip;
  ip = unique(v.begin(), v.begin() + n);
  v.resize(distance(v.begin(), ip));
  cout << v.size() << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <list>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
int main() {
  int long x;
  list<string> name;
  string tmp;
  cin >> x;
  for (int i = 0; i < x; i++) {
    cin >> tmp;
    name.push_back(tmp);
  }
  if (2 < name.size()) {
    name.sort();
  }
  name.unique();
  cout << name.size() << endl;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
int main() {
  int long x;
  vector<string> name;
  string tmp;
  cin >> x;
  cin >> tmp;
  name.push_back(tmp);
  for (int i = 1; i < x; i++) {
    cin >> tmp;
    for (int j = 0; j < name.size(); j++) {
      if (tmp == name[j]) {
        break;
      } else if (j + 1 == name.size()) {
        name.push_back(tmp);
      }
    }
  }
  cout << name.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;
  cin >> N;

  set<string> S;
  rep(i, N) {
    string s;
    cin >> s;
    S.insert(s);
  }
  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() {
  /* Input */
  int N;
  cin >> N;

  vector<string> s(N);
  vector<string> keihin;
  rep(i, N) cin >> s.at(i);
  sort(s.begin(), s.end());

  rep(i, N) {
    bool same_flag = false;
    rep(j, keihin.size()) {
      if (keihin.at(j) == s.at(i)) {
        same_flag = true;
        break;
      }
    }
    if (!same_flag) {
      keihin.push_back(s.at(i));
    }
  }

  /* Output */
  cout << keihin.size() << endl;

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

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

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

Error: TLE

Fixed submission:

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

int main() {
  int n, i, j, ans, check;
  cin >> n;
  string s[n];
  ans = 1;
  cin >> s[0];
  for (i = 1; i < n; i++) {
    cin >> s[i];
    check = 0;
    for (j = 0; j < i; j++) {
      if (s[i] == s[j]) {
        check = 1;
      }
    }
    if (check == 0) {
      ans += 1;
    }
  }
  cout << ans;
}
Problem p02701 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  string s[n];
  map<string, int> m;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  for (int i = 0; i < n; i++) {
    m[s[i]]++;
  }
  cout << m.size() << endl;
  return 0;
}


Error: 0

Fixed submission:

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

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

int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  rep(i, n) 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:

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

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

  int count = 0;
  bool flag;
  rep(i, n) {
    flag = false;
    rep(j, i) {
      if (s[i] == s[j]) {
        flag = true;
        continue;
      }
    }
    if (!flag)
      count++;
  }

  cout << count << endl;

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

#include <iostream>
#include <string>
#include <unordered_map>

using namespace std;
int main() {
  long long n;
  string str;
  unordered_map<string, bool> kuji;

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

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


Error: TLE

Fixed submission:

#include <iostream>
#include <string>

using namespace std;
int main() {
  long long n, cnt = 0;
  string s[200010], str;

  cin >> n;
  for (long long i = 0; i < n; i++) {
    bool flag = false;
    cin >> str;
    for (int i = 0; i < cnt; i++) {
      if (s[i] == str)
        flag = true;
    }
    if (!flag) {
      s[cnt] = str;
      cnt++;
    }
  }

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

#include <algorithm>
#include <bits/stdc++.h>
#include <cstdio>
#include <functional>
#include <iostream>
#include <limits>
#include <numeric>
#include <queue>
#include <type_traits>
#include <vector>

using namespace std;
typedef long long ll;
#define rep(i, n, s) for (int i = s; i < (int)(n); i++)

ll calcNumOfCombination(ll n, ll r) {
  ll num = 1;
  for (ll i = 1; i <= r; i++) {
    num = num * (n - i + 1) / i;
  }
  return num;
}

int gcd(int x, int y) { return (x % y) ? gcd(y, x % y) : y; }

int findSumDigits(int s) {
  int num = 0;
  int temp = 0;
  while (s) {
    temp = s % 10;
    num += temp;
    s = s / 10;
  }
  return num;
}

int countDivisorNum(int n) {
  int count = 0;
  for (int i = 1; i <= n; i++) {
    if (n % i == 0) {
      count++;
    }
  }
  return count;
}

int main() {
  int n;
  cin >> n;
  string s[n];
  rep(i, n, 0) cin >> s[i];
  int ans = 0;
  unordered_set<string> set;
  set.insert(s[0]);
  auto ite = set.begin();

  rep(j, n, 1) {
    ite = set.find(s[j]);
    if (ite != set.end()) {

    } else {
      set.insert(s[j]);
    }
  }

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

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bits/stdc++.h>
#include <cstdio>
#include <functional>
#include <iostream>
#include <limits>
#include <numeric>
#include <queue>
#include <type_traits>
#include <vector>

using namespace std;
typedef long long ll;
#define rep(i, n, s) for (int i = s; i < (int)(n); i++)

ll calcNumOfCombination(ll n, ll r) {
  ll num = 1;
  for (ll i = 1; i <= r; i++) {
    num = num * (n - i + 1) / i;
  }
  return num;
}

int gcd(int x, int y) { return (x % y) ? gcd(y, x % y) : y; }

int findSumDigits(int s) {
  int num = 0;
  int temp = 0;
  while (s) {
    temp = s % 10;
    num += temp;
    s = s / 10;
  }
  return num;
}

int countDivisorNum(int n) {
  int count = 0;
  for (int i = 1; i <= n; i++) {
    if (n % i == 0) {
      count++;
    }
  }
  return count;
}

int main() {
  int n;
  cin >> n;
  string s[n];
  rep(i, n, 0) cin >> s[i];
  int ans = 0;
  list<string> lst;
  lst.push_back(s[0]);
  auto ite = lst.begin();

  rep(j, n, 1) {
    ite = find(lst.begin(), lst.end(), s[j]);
    if (ite != lst.end()) {

    } else {
      lst.push_back(s[j]);
    }
  }

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

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

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


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int c = 0, l, i, x, j;
  string s1, m, n;
  vector<string> s, s2, s3;
  int t;
  cin >> t;
  while (t--) {
    cin >> s1;
    s.push_back(s1);
  }
  l = s.size();

  for (i = 0; i < l; i++) {
    x = s3.size();
    c = 0;
    m = s.at(i);
    for (j = 0; j < x; j++) {
      n = s3.at(j);
      if (m.compare(n) == 0) {
        c++;
        break;
      }
    }
    if (c == 0) {
      s3.push_back(m);
    }
  }
  int p = s3.size();
  cout << p << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int N, sum;
  sum = 1;
  cin >> N;
  vector<string> S(N);
  for (int j = 0; j < N; j++) {
    cin >> S.at(j);
  }
  sort(S.begin(), S.end());

  // 何もらったか判定
  for (int i = 1; i < N; i++) {
    if (S.at(i - 1) != S.at(i)) {
      sum++;
    }
  }

  cout << sum << endl;
}


Error: 0

Fixed submission:

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

int main() {
  int N, sum;
  sum = 0;
  vector<string> S(N);
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> S.at(i);
  }

  // 何もらったか判定
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (S.at(i) != S.at(j) && i > j) {
        sum++;
        break;
      }
    }
  }

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

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

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


Error: TLE

Fixed submission:

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

int main() {
  int n;
  bool a;
  string sub;
  cin >> n;
  vector<string> s(n);
  cin >> s.at(0);
  for (int i = 1; i < n; i++) {
    cin >> sub;
    a = true;
    for (int j = 0; j < i; j++) {
      if (sub == s.at(j)) {
        n--;
        i--;
        a = false;
        break;
      }
    }
    if (a) {
      s.at(i) = sub;
    }
  }
  cout << n << 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;
  string s[n];
  for (int i = 0; i < n; i++)
    cin >> s[i];
  int count = n;
  sort(s, s + n);
  for (int i = 1; i < n; i++) {
    if (s[i - 1] == s[i]) {
      count--;
    }
  }
  cout << count << 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 count = n;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (s[i] != "A" && s[i] == s[j]) {
        count--;
        s[j] = "A";
      }
    }
  }
  cout << count << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

#include <iostream>
using namespace std;
int main() {
  int64_t n;
  cin >> n;
  vector<string> s(n);
  for (auto &si : s) {
    cin >> si;
  }
  sort(s.begin(), s.end());
  uint64_t n_types = 1;
  for (uint64_t i = 1; i < n; ++i) {
    if (s[i] != s[i - 1]) {
      n_types++;
    }
  }
  cout << n_types << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

#include <iostream>
using namespace std;
int main() {
  int64_t n;
  cin >> n;
  vector<string> type;
  type.reserve(2 * pow(10, 5));
  for (int64_t i = 0; i < n; ++i) {
    string si;
    cin >> si;
    bool is_exist = false;
    for (auto type_i : type) {
      if (type_i == si) {
        is_exist = true;
      }
    }
    if (!is_exist) {
      type.emplace_back(si);
    }
  }
  cout << type.size() << endl;
  return 0;
}