alexjercan/bugnet huggingface dataset:
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 < (int)(n); i++)
#define repp(i, n) for (int i = 1; i <= (int)(n); i++)
#define co(x) cout << x << endl
typedef long long int lint;

int main() {
  int N;
  cin >> N;
  vector<string> S(N);
  rep(i, N) { cin >> S.at(i); }
  sort(S.begin(), S.end());
  S.erase(unique(S.begin(), S.end()), S.end());
  co(S.size());
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repp(i, n) for (int i = 1; i <= (int)(n); i++)
#define co(x) cout << x << endl
typedef long long int lint;

int main() {
  int N;
  cin >> N;
  vector<string> S(0);
  string si;
  bool flg = true;

  for (int i = 0; i < N; i++) {
    cin >> si;
    flg = true;
    for (int j = 0; j < S.size(); j++) {
      if (S.at(j) == si) {
        flg = false;
        break;
      }
    }
    if (flg == true) {
      S.push_back(si);
    }
  }
  co(S.size());
}
Problem p02701 (C++) — buggy submission, verdict: Runtime Error

#include "bits/stdc++.h"
#include <string>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
void sort2array(double *a, long *b, long n) {
  for (int i = 0; i < n; i++) {
    b[i] = i;
  }
  sort(b, b + n, [a](long i, long j) -> bool { return a[i] < a[j]; });
}
// bを何回足せばaを超えるか
int wtover(int a, int b) {
  if (a % b > 0)
    return (a / b) + 1;
  else
    return a / b;
}
const int INF = 100000001, ID_MAX = 20;
int bi_e[ID_MAX] = {0};
// 2進数表示したときの最高桁
int bi_max(long n) {
  int m = 0;
  for (m; pow(2, m) <= n; m++)
    ;
  m = m - 1;
  return m;
}
// bi_eに二進数表示したやつを代入
void bi_exs(long n) {
  rep(i, ID_MAX) { bi_e[i] = 0; }
  if (n < pow(2, ID_MAX)) {
    int m = bi_max(n);
    long l;
    for (m; m > -1; m--) {
      l = pow(2, m);
      bi_e[m] = n / l;
      n = n % l;
    }
  }
}
// x^n mod m (nが負の時は０)
long myPow(long x, long n, long m) {
  if (n < 0)
    return 0;
  if (n == 0)
    return 1;
  if (n % 2 == 0)
    return myPow(x * x % m, n / 2, m);
  else
    return x * myPow(x, n - 1, m) % m;
}

int main() {
  int i;
  // 入力
  int n;
  cin >> n;
  vector<string> s;
  string b;
  for (int i = 0; i < n; i++) {
    cin >> b;
    s.push_back(b);
  }
  // 処理
  sort(s.begin(), s.end());
  int cou = 0;
  string a;
  rep(i, n) {
    if (a != s[i]) {
      cou++;
      a = s[i];
    }
  }
  // 出力
  cout << cou << endl;
}

Error: WA

Fixed submission:

#include "bits/stdc++.h"

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
void sort2array(double *a, long *b, long n) {
  for (int i = 0; i < n; i++) {
    b[i] = i;
  }
  sort(b, b + n, [a](long i, long j) -> bool { return a[i] < a[j]; });
}
// bを何回足せばaを超えるか
int wtover(int a, int b) {
  if (a % b > 0)
    return (a / b) + 1;
  else
    return a / b;
}
const int INF = 100000001, ID_MAX = 20;
int bi_e[ID_MAX] = {0};
// 2進数表示したときの最高桁
int bi_max(long n) {
  int m = 0;
  for (m; pow(2, m) <= n; m++)
    ;
  m = m - 1;
  return m;
}
// bi_eに二進数表示したやつを代入
void bi_exs(long n) {
  rep(i, ID_MAX) { bi_e[i] = 0; }
  if (n < pow(2, ID_MAX)) {
    int m = bi_max(n);
    long l;
    for (m; m > -1; m--) {
      l = pow(2, m);
      bi_e[m] = n / l;
      n = n % l;
    }
  }
}
// x^n mod m (nが負の時は０)
long myPow(long x, long n, long m) {
  if (n < 0)
    return 0;
  if (n == 0)
    return 1;
  if (n % 2 == 0)
    return myPow(x * x % m, n / 2, m);
  else
    return x * myPow(x, n - 1, m) % m;
}

int main() {
  int i;
  // 入力
  int n;
  cin >> n;
  vector<char *> s;
  char *b;
  rep(i, n) {
    cin >> b;
    s.push_back(b);
  }
  // 処理
  sort(s.begin(), s.end());
  int cou = 0;
  char a[11] = {0};
  rep(i, n) {
    if (strcmp(a, s[i]) != 0) {
      cou++;
      strcpy(a, s[i]);
    }
  }
  // 出力
  cout << cou << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  long N;
  cin >> N;
  vector<string> S(N);
  string buf;
  for (long i = 0; i < N; i++) {
    cin >> buf;
    S[i] = buf;
  }
  sort(S.begin(), S.end());

  long ans = N;
  for (long i = 1; i < N; i++) {
    if (S[i] == S[i - 1]) {
      ans--;
    }
  }
  cout << ans << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  long N;
  cin >> N;
  vector<string> S(0);
  for (int i = 0; i < N; i++) {
    string buf;
    cin >> buf;
    if (find(S.begin(), S.end(), buf) == S.end()) {
      S.push_back(buf);
    }
  }
  cout << S.size() << endl;
  return 0;
}
Problem p02701 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  string s;
  set<string> gchga;
  while (n--) {
    cin >> s;
    gchga.insert(s);
  }
  cout << gchga.size() << endl;
  return 0;
}


Error: 0

Fixed submission:

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

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

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


Error: TLE

Fixed submission:

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

int main() {
  long long n, ans;
  cin >> n;
  ans = n;
  vector<string> vec(n);
  for (long long i = 0; i < n; i++) {
    cin >> vec.at(i);
  }
  for (long long i = 0; i < n - 1; i++) {
    for (long long k = i + 1; k < n; k++) {
      if (vec.at(i) == vec.at(k)) {
        if (vec.at(k) == " ") {
          continue;
        }
        vec.at(k) = " ";
        ans--;
      }
    }
  }
  cout << ans << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

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


Error: TLE

Fixed submission:

#include <iostream>
#include <string>
using namespace std;
int main() {
  int n, ans = 0;
  cin >> n;
  const int N = n;
  string s[N];
  for (int i = 0; i < N; i++) {
    cin >> s[i];
    ans++;
    for (int j = 0; j < i; j++) {
      if (s[j] == s[i]) {
        ans--;
        break;
      }
    }
  }
  cout << ans << 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;
typedef long long ll;

const int INF = 1001001001;
const int mod = 1000000007;

ll pow(ll base, ll order) {
  ll ans = 1;
  rep(i, order - 1) ans *= base;
  return ans;
}

int gcd(int a, int b) {
  if (a < b) {
    int c = a;
    a = b;
    b = c;
  }
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

ll sum(ll x) { // sum of subsequent numbers from 0 to x
  return x * (x + 1) / 2;
}

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

  vector<string> ordered(n);
  queue<string> que;
  rep(i, n) {
    string s;
    cin >> ordered.at(i);
  }
  sort(ordered.begin(), ordered.end());
  // rep(i,n) cout << ordered.at(i) << endl;
  rep(i, n) que.push(ordered.at(i));

  int kind = 0;
  while (!que.empty()) {
    string ref;
    ref = que.front();
    que.pop();
    kind++;
    int current_size = que.size();
    rep(i, current_size) {
      string current = que.front();
      if (ref == current)
        que.pop();
      else
        break;
    }
  }
  cout << kind << endl;
}


Error: TLE

Fixed submission:

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

const int INF = 1001001001;
const int mod = 1000000007;

ll pow(ll base, ll order) {
  ll ans = 1;
  rep(i, order - 1) ans *= base;
  return ans;
}

int gcd(int a, int b) {
  if (a < b) {
    int c = a;
    a = b;
    b = c;
  }
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

ll sum(ll x) { // sum of subsequent numbers from 0 to x
  return x * (x + 1) / 2;
}

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

  queue<string> que;
  rep(i, n) {
    string s;
    cin >> s;
    que.push(s);
  }

  int kind = 0;
  while (!que.empty()) {
    string ref;
    ref = que.front();
    que.pop();
    kind++;
    int current_size = que.size();
    rep(i, current_size) {
      string current = que.front();
      if (ref == current)
        que.pop();
      else {
        que.push(current);
        que.pop();
      }
    }
  }
  cout << kind << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
#include <set>
int main(void) {
  set<string> item;
  int n;
  cin >> n;
  // bool exist = false;
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    string str;
    cin >> str;
    set<string>::iterator iti = item.find(str);
    if (iti == item.end()) {
      item.insert(str);
      cnt++;
    }
  }
  cout << cnt << endl;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main(void) {
  int N;
  string item[250000];
  cin >> N;
  bool exist = false;
  int cnt = 0;
  for (int i = 0; i < N; i++) {
    string str;
    cin >> str;
    // cout << str << endl;
    if (i != 0) {
      for (int j = 0; j < i; j++) {
        if (str == item[j]) {
          // cout << "exist" << endl;
          exist = true;
          break;
        }
      }
      if (!exist) {
        // cout << "not_exist" << endl;
        cnt++;
        item[i] = str;
      }
    } else {
      // cout << "not_exist" << endl;
      cnt++;
      item[i] = str;
    }
  }
  cout << cnt << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

//
// AtCoder Beginner Contest 164
// C - gacha
//

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define reAll(x) (x).rbegin(), (x).rend()

using ll = long long;

const double PI = 3.14159265358979323846;
const int MOD = 1000000007;

int main() {
  int n;

  cin >> n;

  vector<string> s(n);

  int ans = 0;

  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:

//
// AtCoder Beginner Contest 164
// C - gacha
//

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define reAll(x) (x).rbegin(), (x).rend()

using ll = long long;

const double PI = 3.14159265358979323846;
const int MOD = 1000000007;

int main() {
  int n;

  cin >> n;

  string s;
  vector<string> stmp;

  int ans = 0;

  rep(i, n) {
    cin >> s;

    auto result = find(stmp.begin(), stmp.end(), s);
    if (result == stmp.end()) {
      stmp.push_back(s);
      ans++;
    }
  }

  cout << ans << endl;

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

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

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

  vector<string> ans;
  for (int i = 0; i < n; i++) {
    string t;
    cin >> t;
    ans.push_back(t);
  }

  set<string> s;
  for (string x : ans) {
    s.insert(x);
  }
  cout << s.size() << endl;
}


Error: TLE

Fixed submission:

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

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

  vector<string> ans;
  for (int i = 0; i < n; i++) {
    string t;
    cin >> t;
    ans.push_back(t);
  }
  bool flag = true;
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    for (int k = i - 1; k >= 0; k--) {
      if (ans[k] == ans[i]) {
        flag = false;
        break;
      }
    }
    if (flag) {
      cnt++;
    }
    flag = true;
  }
  cout << cnt << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

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 ind = 0;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < i; j++) {
      if (s[i] == s[j])
        ind = 1;
    }
    if (ind == 0)
      ans++;
  }
  cout << ans << endl;
  return 0;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;
using vi = vector<int>;
using vvi = vector<vector<int>>;

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i > 0; i--)
#define all(v) v.begin(), v.end()
#define debug(x) cout << x << endl
#define vout(v) rep(i, v.size()) cout << v[i] << " "

const int MAX = 1000000;
int n;

int main() {
  cin >> n;
  vector<string> s(n);
  int ans = 0;
  rep(i, n) { cin >> s[i]; }
  sort(all(s));
  s.erase(unique(all(s)), s.end());
  cout << s.size();

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
using vi = vector<int>;
using vvi = vector<vector<int>>;

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i > 0; i--)
#define all(v) v.begin(), v.end()
#define debug(x) cout << x << endl
#define vout(v) rep(i, v.size()) cout << v[i] << " "

const int MAX = 1000000;
int n;

int main() {
  cin >> n;
  vector<string> ss;
  string s;
  int ans = 0;
  rep(i, n) {
    cin >> s;
    if (count(all(ss), s)) {
    } else {
      ans++;
      ss.push_back(s);
    }
  }
  cout << ans;

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

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

int main() {
  int n;
  cin >> n;
  map<string, int> T;
  for (int i = 0; i < n; i++) {
    string buf;
    cin >> buf;
    auto target = T.find(buf);
    if (target == T.end()) {
      T.insert(make_pair(buf, 1));
    }
  }
  cout << T.size() << endl;
  return 0;
}


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++) {
    string buf;
    cin >> buf;
    auto itr = find(s.begin(), s.end(), buf);
    if (itr == s.end()) {
      s.push_back(buf);
    }
  }
  cout << s.size() - n << endl;
  return 0;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int main() {
  int n, i, count = 0;
  cin >> n;
  string s[n];
  for (i = 0; i < n; i++)
    cin >> s[i];
  sort(s, s + n);
  for (i = 0; i < n; i++) {
    if (!binary_search(s, s + i, s[i]))
      count++;
  }
  cout << count;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int isunique(string *s, int j) {
  int i;
  if (j == 0)
    return 1;
  for (i = 0; i < j; i++) {
    if (s[i].compare(s[j]) == 0)
      return 0;
  }
  return 1;
}
int main() {
  int n, i, count = 0;
  cin >> n;
  string s[n];
  for (i = 0; i < n; i++)
    cin >> s[i];
  for (i = 0; i < n; i++) {
    if (isunique(s, i))
      count++;
  }
  cout << count;
}
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 t;
  for (int i = 0; i < n; i++) {
    cin >> t;
    s.insert(t);
  }
  cout << s.size() << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<string> s;
  string s1;
  std::vector<string>::iterator it;
  for (int i = 0; i < n; i++) {
    cin >> s1;
    string t = s1;
    it = std::find(s.begin(), s.end(), t);
    if (it != s.end()) {
    } else {
      s.push_back(t);
    }
  }
  cout << s.size() << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Runtime Error

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

signed main() {
  int N;
  cin >> N;
  vector<string> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  sort(A.begin(), A.end());

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

Error: -6
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc


Fixed submission:

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

signed main() {
  int N;
  vector<string> A(N);
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  sort(A.begin(), A.end());

  int C = 1;
  for (int i = 0; i < N - 1; i++) {
    if (A.at(i) != A.at(i + 1)) {
      C++;
    }
  }
  cout << C << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  int cnt = 1;
  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))
      cnt++;
  }

  cout << cnt << endl;
}


Error: TLE

Fixed submission:

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

int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  int cnt = 1;
  for (int i = 0; i < n; i++) {
    cin >> s.at(i);
    bool diff = true;
    if (i != 0) {
      for (int j = 0; j < i; j++) {
        if (s.at(j) == s.at(i)) {
          diff = false;
        }
        if (!diff)
          break;
      }
      if (diff)
        cnt++;
    }
  }

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

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

int main() {
  int n, count = 0, after_size;
  bool flg = false;
  cin >> n;
  vector<string> si;
  string atari;

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

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

  after_size = si.size();

  cout << after_size << endl;
}


Error: TLE

Fixed submission:

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

int main() {
  int n, count = 0, flg = 0;
  cin >> n;
  string si[n], atari;

  for (int i = 0; i < n; i++) {
    cin >> atari;
    for (int j = 0; j < count; j++) {
      if (atari.compare(si[j]) == 0) {
        flg = 1;
        break;
      }
    }

    if (flg == 1) {
      flg = 0;
      continue;
    } else {
      si[count] = atari;
      count = count + 1;
    }
  }
  cout << count << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <math.h>
#include <string>
using namespace std;
class Tree {
public:
  string s;
  Tree *left = NULL, *right = NULL;
  Tree(string word) { s = word; }
  int check(string word) {
    if (word == s) {
      return 0;
    } else if (word < s) {
      if (left == NULL) {
        left = new Tree(word);
        return 1;
      } else {
        return left->check(word);
      }
    } else {
      if (right == NULL) {
        right = new Tree(word);
        return 1;
      } else {
        return right->check(word);
      }
    }
  }
};
int main() {
  int n;
  cin >> n;
  string s[n], sc;
  int i, j, p = 1;
  cin >> sc;
  Tree root(sc);
  for (i = 1; i < n; i++) {
    cin >> sc;
    p += root.check(sc);
  }
  cout << p << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <math.h>
#include <string>
using namespace std;
int main() {
  int n;
  cin >> n;
  string s[n], sc;
  int i, j, p = 0;
  for (i = 0; i < n; i++) {
    cin >> sc;
    bool flg = true;
    for (j = 0; j < p; j++) {
      if (s[j] == sc) {
        flg = false;
        break;
      }
    }
    if (flg) {
      s[p] = sc;
      p++;
    }
  }
  cout << p << endl;
  return 0;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;

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());

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

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

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;
using ll = long long;

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

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

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

  sort(S, S + N);

  int cnt = 1;
  for (int i = 0; i < N - 1; i++) {
    if (S[i] != S[i + 1])
      cnt++;
  }

  cout << cnt << endl;
}

Error: -6
*** stack smashing detected ***: terminated


Fixed submission:

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

int main() {
  int N;

  cin >> N;
  string S[N];

  int num[] = {};

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

    for (int j = 0; j < N; j++) {
      if (S[i] != S[j]) {
        num[i]++;
      } else if (S[i] == S[j]) {
        num[j]++;
        break;
      }
    }
  }

  int res = 0;
  for (int i = 0; i < N; i++) {
    if (num[i] > 0)
      res++;

    // cout << "num[" << i << "]=" << num[i]<<endl;
  }

  cout << res << endl;
}
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;

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

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

  return 0;
}

Error: TLE

Fixed submission:

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

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

  int n, count;
  cin >> n;
  count = n;
  vector<string> s(n);
  rep(i, n) {
    cin >> s.at(i);
    if (i) {
      rep(j, i) {
        if (s.at(i) == s.at(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() {
  int n;
  cin >> n;
  vector<string> s(n);
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }

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

  cout << n - d << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  int n;
  cin >> n;
  string s;
  vector<string> l;
  for (int i = 0; i < n; i++) {
    cin >> s;
    bool flag = true;
    for (int j = 0; j < l.size(); j++) {
      if (s == l[j]) {
        flag = false;
        break;
      }
    }
    if (flag)
      l.push_back(s);
  }
  cout << l.size() << endl;
}