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

#include <algorithm>
#include <cstring>
#include <stdio.h>
#include <string>
#include <vector>

using namespace std;
typedef long long llong;

#define MAX 200001
const llong mod = 1000000000 + 7;

int main() {
  int N, flag = 1, ans = 0;
  char S[11];
  vector<string> v;

  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%s", &S);
    v.push_back(S);
  }

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

  string a = "";
  for (auto str : v) {
    if (str.compare(a))
      ans++;
    a = str;
  }

  printf("%d\\n", ans);

  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <cstring>
#include <string>
#include <vector>

using namespace std;
typedef long long llong;

#define MAX 200001
const llong mod = 1000000000 + 7;

int main() {
  int N, flag = 1, ans = 0;
  char S[11];
  vector<string> v;

  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%s", &S);
    flag = 1;
    for (int j = 0; j < ans; j++) {
      if (strcmp(S, v[j].c_str()) == 0) {
        flag = 0;
        break;
      }
    }

    if (flag) {
      v.push_back(S);
      ans++;
    }
  }

  printf("%d\\n", ans);

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

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

int main() {
  int n = 0, ans = 0;
  string str;
  cin >> n;
  vector<string> a(n, "");

  for (int i = 0; i < n; ++i) {
    cin >> a.at(i);
    /*
    for (int j=0; j<n; ++j){
      if (str == a.at(j)) break;
      else if (j == n - 1){
        a.at(ans) = str;
        ++ans;
      }
    }
    */
  }

  sort(a.begin(), a.end());
  str = a.at(0);
  for (int i = 0; i < n; ++i) {
    // cout << a.at(i)<<endl;
    if (a.at(i) != str) {
      str = a.at(i);
      ++ans;
    }
  }

  cout << ans + 1 << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  int n = 0, ans = 0;
  string str;
  cin >> n;
  vector<string> a(n, "");

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

#include <iostream>
#include <set>
#include <string>
#include <vector>
// #include "./libb/lib.hpp"

using namespace std;

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

  int ans = 0;
  // ans = nn;

  set<string> sary;
  string str_tmp;
  int sum = 0;

  for (int i = 0; i < nn; i++) {
    cin >> str_tmp;
    sary.insert(str_tmp);
  }

  for (auto itr = sary.begin(); itr != sary.end(); ++itr) {
    sum++;
  }

  cout << sum << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>
#include <vector>
// #include "./libb/lib.hpp"

using namespace std;

int main() {
  uint32_t nn;
  cin >> nn;

  uint32_t ans = 0;
  ans = nn;

  vector<string> sary(nn);
  vector<uint32_t> check(nn, 1);
  vector<uint32_t> sum(nn, 1);

  for (uint32_t i = 0; i < nn; i++) {
    cin >> sary[i];
  }

  for (uint32_t i = 0; i < nn; i++) {
    for (uint32_t k = (i + 1); k < nn; k++) {
      if (check[i] == 1) {
        if (!(sary[i].compare(sary[k]))) {
          check[k] = 0;
          // sum[k] = 0;
          ans--;
        }
      }
    }
  }

  //    for(uint32_t l = 0; l < nn; l++){
  //        ans += sum[l];
  //    }

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

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

#define ll long long

int main() {

  ll N;
  cin >> N;

  set<string> sp;
  string S;

  for (ll i = 0; i < N; i++) {
    cin >> S;
    sp.insert(S);
  }

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

Error: TLE

Fixed submission:

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

#define ll long long

int main() {

  ll N;
  cin >> N;

  std::string S[N];

  cin >> S[0];

  int sp = 0;
  std::string spi[N];

  sp++;
  spi[0] = S[0];

  for (ll i = 1; i <= N - 1; i++) {
    cin >> S[i];
    for (int j = 0; j < sp; j++) {
      if (S[i] == spi[j]) {
        break;
      }
      if (j == sp - 1) {
        if (S[i] != spi[j]) {
          sp++;
          spi[sp - 1] = S[i];
        }
      }
    }
  }

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

#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <vector>
using namespace std;

int main() {
  int n;
  cin >> n;
  string s[200000], a;
  int sum = 0;

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

  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <vector>
using namespace std;

int main() {
  int n;
  cin >> n;
  string s[200000], a;
  int sum = 0;

  for (int i = 0; i < n; i++) {
    cin >> a;
    if (i == 0) {
      s[0] = a;
      sum++;
    }
    int b = 0;
    for (int j = 0; j < sum; j++) {
      if (a == s[j])
        b = 1;
    }
    if (b == 0) {
      s[sum] = a;
      sum++;
    }
  }
  cout << sum << endl;

  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;

  set<string> st;

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

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

  return 0;
}

Error: TLE

Fixed submission:

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

using namespace std;

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

  string s[2 * 100000];
  int count = 0;
  for (int i = 0; i < n; i++) {
    string tmp;
    cin >> tmp;

    bool judge = false;
    for (int j = 0; j < count; j++) {
      if (s[j] == tmp) {
        judge = true;
        break;
      }
    }
    if (!judge) {
      s[count] = tmp;
      count++;
    }
  }

  cout << count << endl;

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

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

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


Error: 0

Fixed submission:

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

int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  rep(i, n) cin >> s.at(i);
  sort(s.begin(), s.end());
  int ans = n;
  rep(i, n) {
    if (s[i] == s[i - 1])
      ans--;
  }
  cout << ans << endl;
}
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> s(n);
  for (int i = 0; i < n; i++) {
    cin >> s.at(i);
  }
  sort(s.begin(), s.end());
  int count = 1;
  for (int i = 0; i < n - 1; i++) {
    if (s.at(i) != s.at(i + 1)) {
      count++;
    }
  }
  cout << count << endl;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;

int main() {
  int n;
  cin >> n;
  char s[n][10];
  int count = n;
  bool flag = true;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    for (int j = 0; j < i; j++) {
      flag = true;
      if (strcmp(s[i], s[j]) == 0) {
        flag = false;
        break;
      }
    }
    if (!flag)
      count--;
  }
  cout << count << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); i++)
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>
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); i++)
using namespace std;

int main() {
  int n;
  cin >> n;
  string s[200200];
  int count = 0;
  rep(i, n) {
    cin >> s[i];
    count++;
    if (i == 0)
      continue;
    rep(j, i) {
      if (s[i] == s[j]) {
        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(void) {
  int n;
  string input;
  vector<string> s;
  int count = 0;

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

  sort(s.begin(), s.end());
  for (int i = 1; i < s.size(); i++) {
    if (s[i] != s[i - 1]) {
      count++;
    }
  }
  cout << count + 1 << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main(void) {
  int n;
  string input;
  vector<string> s;
  int flag = 0;

  cin >> n;
  cin >> input;
  s.push_back(input);
  for (int i = 1; i < n; i++) {
    cin >> input;
    for (int j = 0; j < s.size(); j++) {
      if (s[j] == input) {
        flag = 1;
      }
    }
    if (flag == 0) {
      s.push_back(input);
    } else {
      flag = 0;
    }
  }
  cout << s.size() << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

#include <map>
#include <string>

using namespace std;

int main() {
  map<string, int> strs;
  string tmp;
  int n, ans = 0;

  cin >> n;

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

    strs.emplace(tmp, 0);
  }

  cout << strs.size() << "\\n";

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

#include <string>
#include <vector>

using namespace std;

int main() {
  vector<string> strs;
  string tmp;
  int n, ans = 0;

  cin >> n;

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

    cin >> tmp;

    bool end = false;
    for (const auto &s : strs) {
      if (tmp == s) {
        end = true;
      }
    }

    if (end)
      continue;

    strs.emplace_back(tmp);
  }

  cout << strs.size() << "\\n";

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

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

int main() {
  long N;
  cin >> N;
  string goods[N];

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

  map<string, long> count;
  long result = 0;

  for (int i = 0; i < N; i++) {
    if (count[goods[i]] == 1) {
      result = result;
    } else {
      count[goods[i]] = 1;
      result += 1;
    }
  }

  cout << result << endl;

  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  long N;
  cin >> N;
  string goods[N];

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

  long long result = 0;
  int j = 0;

  for (int i = 0; i < N; i++) {
    for (j = i + 1; j < N; j++) {
      if (goods[i] == goods[j]) {
        break;
      }
    }
    if (j == N) {
      result += 1;
    }
  }

  cout << result << endl;

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

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
const int N = 2e6 + 5;
int a[N][26];
int cnt[N], idx, ans;
void ins(char str[]) {
  int p = 0;
  for (int i = 0; str[i]; i++) {
    int u = str[i] - 'a';
    if (!a[p][u])
      a[p][u] = ++idx;
    p = a[p][u];
  }
  cnt[p]++;
  if (cnt[p] == 1)
    ans++;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    char str[12];
    scanf("%s", str);
    ins(str);
  }
  cout << ans;
  return 0;
}


Error: WA

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
const int N = 2e5 + 5;
int a[N][26];
int cnt[N], idx, ans;
void ins(char str[]) {
  int p = 0;
  for (int i = 0; str[i]; i++) {
    int u = str[i] - 'a';
    if (!a[p][u])
      a[p][u] = ++idx;
    p = a[p][u];
  }
  cnt[p]++;
  if (cnt[p] == 1)
    ans++;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    char str[12];
    scanf("%s", str);
    ins(str);
  }
  cout << ans;
  return 0;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n, x;
  cin >> n;
  x = n;
  vector<string> s(n);
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  sort(s.begin(), s.end());
  for (int i = 0; i < n - 1; i++) {
    if (s[i] == s[i + 1]) {
      x--;
    }
  }

  cout << x << endl;
}


Error: TLE

Fixed submission:

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

int main() {
  int n, x = 1;
  cin >> n;
  string s[n], t[n];
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  t[0] = s[0];
  for (int i = 1; i < n; i++) {
    x++;
    for (int ii = 0; ii < x - 1; ii++) {
      if (s[i] == t[ii]) {
        x--;
        break;
      }
      if (ii + 1 == x) {
        t[x] = s[i];
      }
    }
  }

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

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

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

int main(int argc, char *argv[]) {
  std::string str;
  int N = 0;
  std::vector<string> v;
  std::map<std::string, int> m;

  cin >> N;
  for (int i = 1; i <= N; i++) {
    string tmp;
    cin >> tmp;
    try {
      m.at(tmp);
    } catch (std::out_of_range &) {
      m.insert(std::make_pair(tmp, 0));
    }
  }
  int ans = m.size();
  printf("%d\\n", ans);

  return 0;
}

Error: TLE

Fixed submission:

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

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

int main(int argc, char *argv[]) {
  std::string str;
  int N = 0;
  std::vector<string> v;

  cin >> N;
  cin >> str;
  v.push_back(string(str.c_str()));

  int ans = 1;
  for (int i = 2; i <= N; i++) {
    int s = 0;
    int e = v.size();
    string tmp;
    cin >> tmp;
    for (; e - s > 1;) {
      int m = (s + e) / 2;
      if (strcmp(tmp.c_str(), v[m].c_str()) < 0) {
        e = m;
      } else {
        s = m;
      }
    }
    int cmp = strcmp(tmp.c_str(), v[s].c_str());
    if (cmp < 0) {
      v.insert(v.begin() + s, tmp);
      ans++;
    } else {
      if (cmp != 0) {
        if (s == v.size() - 1) {
          ans++;
        } else {
          if (strcmp(tmp.c_str(), v[s + 1].c_str()) != 0) {
            ans++;
          }
        }
      }
      v.insert(v.begin() + s + 1, tmp);
    }
  }
  printf("%d\\n", ans);
  return 0;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <unordered_map>

int main() {
  std::unordered_map<std::string, int> mp; // ローカル変数として、mp を生成
  std::string s;

  int count = 0;
  int N;
  std::cin >> N;
  for (int i = 0; i < N; i++) {
    std::cin >> s;
    auto itr = mp.find(s); // "xyz" が設定されているか？
    if (itr == mp.end()) {
      mp[s] = 1;
      count++;
    }
  }

  std::cout << count << std::endl;
}

Error: TLE

Fixed submission:

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

int main() {
  char strings[300000][11];
  long long int x;
  scanf("%lld", &x);
  int count = 0;
  char tmp[11] = "";
  for (int i = 0; i < x; i++) {
    scanf("%s", tmp);
    bool same = false;
    for (int j = 0; j < count; j++) {
      if (strcmp(strings[j], tmp) == 0) {
        same = true;
        break;
      }
    }
    if (same == false) {
      strcpy(strings[count], tmp);
      count++;
    }
  }
  printf("%d\\n", count);
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

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

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

  for (int i = 0; i < N; i++) {
    if (i == 0)
      num = 1;
    else if (S.at(i) != S.at(i - 1))
      num++;
  }
  cout << num << endl;
}


Error: TLE

Fixed submission:

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

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

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

    for (int j = 0; j < i; j++) {
      if (S.at(i) == S.at(j)) {
        num--;
        break;
      }
    }
  }

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

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<string> vec(200002);
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> vec[i];
  }
  sort(vec.begin(), vec.end());
  vec.erase(unique(vec.begin(), vec.end()), vec.end());
  cout << vec.size() - 1;
}

Error: WA

Fixed submission:

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<string> vec(20001);
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> vec[i];
  }
  sort(vec.begin(), vec.end());
  vec.erase(unique(vec.begin(), vec.end()), vec.end());
  cout << vec.size() - 1;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define mod 1000000007
#define pi 3.141592653589793
typedef vector<ll> vcl;

ll gcd(ll a, ll b) {
  if (b > a)
    swap(a, b);
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
  ll g = gcd(a, b);
  return a / g * b;
}
ll rep_jijo(ll n, ll x) {
  if (x == 0)
    return 1;
  if (x % 2 == 0) {
    ll t = rep_jijo(n, x / 2);
    return t * t % mod;
  }
  return n * rep_jijo(n, x - 1) % mod;
}

int main() {
  ll n;
  cin >> n;
  set<string> gc;
  string s;
  rep(i, n) {
    cin >> s;
    gc.insert(s);
  }

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


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define mod 1000000007
#define pi 3.141592653589793
typedef vector<ll> vcl;

ll gcd(ll a, ll b) {
  if (b > a)
    swap(a, b);
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
  ll g = gcd(a, b);
  return a / g * b;
}
ll rep_jijo(ll n, ll x) {
  if (x == 0)
    return 1;
  if (x % 2 == 0) {
    ll t = rep_jijo(n, x / 2);
    return t * t % mod;
  }
  return n * rep_jijo(n, x - 1) % mod;
}

int main() {
  ll n;
  cin >> n;
  vector<string> s(n);
  rep(i, n) cin >> s[i];
  rep(i, n) {
    for (ll j = 1; j <= n - 1 - i; j++) {
      if (s[i] == "0") {
        break;
      } else if (s[i] == s[i + j]) {
        s[i + j] = "0";
      }
    }
  }
  ll ans = 0;
  rep(i, n) if (s[i] != "0") { ans++; }
  cout << ans << 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)

int main() {
  int N;
  cin >> N;
  set<string> st;
  string s;

  rep(i, N) {
    cin >> s;
    st.insert(s);
  }

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

Error: TLE

Fixed submission:

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

int main() {
  int N;
  cin >> N;
  vector<string> s(N);
  int count = 1;
  bool ok;
  rep(i, N) cin >> s.at(i);

  for (int i = 1; i < N; i++) {
    ok = true;
    for (int j = 0; j < i; j++) {
      if (s.at(i) == s.at(j)) {
        ok = false;
        // cout<<"no"<<endl;
        break;
      }
    }
    if (ok) {
      count++;
      // cout<<"ok"<<endl;
    }
  }
  cout << count;
}
Problem p02701 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  map<string, long> data;
  long count = 0;
  long n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;

    if (data[s] == 0) {
      data[s] += 1;
      count += 1;
    }
  }
  cout << count << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
#include <stdio.h>
using namespace std;
#define N 20000

int main() {
  int n;
  int ans = 0;
  int count = 0;
  cin >> n;
  string a;
  string kind[11][N]; // kind[u][v]は文字数uのなかのv番目
  int num[20];        // 文字数nの個数
  for (int i = 0; i < 11; i++) {
    num[i] = 0;
  }
  for (int i = 0; i < n; i++) {
    cin >> a;
    int l = a.size();

    for (int i = 0; i < num[l]; i++) {
      if (kind[l][i] == a) {
        ans = 1;
        break;
      }
    }
    if (ans == 0) {
      kind[l][num[l]] = a;
      num[l] += 1;
      count += 1;
    }
  }
  cout << count << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

int main() {

  int64_t n;
  cin >> n;

  string s[200005];
  for (int i = 0; i < n; i++)
    cin >> s[i];
  set<string> values;
  for (int i = 0; i < n; i++) {
    values.insert(s[i]);
  }
  cout << values.size() << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main() {

  int n;
  cin >> n;

  string s[10];
  for (int i = 1; i <= n; i++)
    cin >> s[i];

  set<string> values;
  for (int i = 0; i <= n; i++) {
    values.insert(s[i]);
  }
  cout << values.size() - 1 << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

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

void funcC2() {
  int n;
  std::cin >> n;
  std::vector<std::string> s(n, "");
  bool isOrigin;
  for (int i = 0; i < n; i++) {
    std::cin >> s[i];
  }
  std::sort(s.begin(), s.end());
  int cnt = 1;
  for (int i = 1; i < n; i++) {
    if (s[i - 1] != s[i])
      cnt++;
  }
  std::cout << cnt;
}

int main(void) {
  funcC2();
  return 0;
}

Error: TLE

Fixed submission:

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

void funcC() {
  int n;
  std::cin >> n;
  std::vector<std::string> s = {};
  std::string temp;
  bool isOrigin;
  for (int i = 0; i < n; i++) {
    isOrigin = true;
    std::cin >> temp;
    for (int j = 0; j < s.size(); j++) {
      if (s[j] == temp) {
        isOrigin = false;
        break;
      }
    }
    if (isOrigin)
      s.push_back(temp);
  }
  std::cout << s.size();
}

int main(void) {
  funcC();
  return 0;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const int INF = 1001001001;

ll pow_mod(ll x, ll y) {
  ll res = 1;
  for (ll i = 0; i < y; i++)
    res = res * x % mod;
  return res;
}

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

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const int INF = 1001001001;

ll pow_mod(ll x, ll y) {
  ll res = 1;
  for (ll i = 0; i < y; i++)
    res = res * x % mod;
  return res;
}

int main() {
  int n;
  cin >> n;
  vector<vector<string>> s(26, vector<string>(0));
  for (int i = 0; i < n; i++) {
    string now;
    cin >> now;
    int initial = (int)(now[0] - 'a');
    if (s[initial].size() == 0) {
      s[initial].push_back(now);
    } else {
      bool flag = true;
      for (int j = 0; j < s[initial].size(); j++) {
        if (s[initial][j] == now) {
          flag = false;
          break;
        }
      }
      if (flag)
        s[initial].push_back(now);
    }
  }
  int ans = 0;
  for (int i = 0; i < s.size(); i++)
    ans += s[i].size();
  cout << ans << endl;
  return 0;
}