alexjercan/bugnet huggingface dataset:
Problem p02701 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
const long long mod = 1000000007;
typedef long long int ll;
typedef pair<ll, ll> P;
const vector<int> di = {-1, 0, 1, 0};
const vector<int> dj = {0, 1, 0, -1};
const double PI = 3.14159265358979323846;

int main() {

  ll n;
  cin >> n;
  vector<string> s(n);
  rep(i, n) cin >> s.at(i);

  sort(s.begin(), s.end());
  ll ans = s.size();
  rep(i, n - 1) {
    if (s.at(i) == s.at(i + 1))
      ans--;
  }

  cout << ans << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
const long long mod = 1000000007;
typedef long long int ll;
typedef pair<ll, ll> P;
const vector<int> di = {-1, 0, 1, 0};
const vector<int> dj = {0, 1, 0, -1};
const double PI = 3.14159265358979323846;

int main() {

  ll n;
  cin >> n;
  vector<string> s(n);
  rep(i, n) cin >> s.at(i);

  sort(s.begin(), s.end());
  int num = 0;
  while (1) {
    if (s.at(num) == s.at(num + 1)) {
      s.erase(s.begin() + num);
      num--;
    }
    num++;
    if (num == (s.size() - 1))
      break;
  }

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

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

#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<string> S(N);

  for (int k = 0; k < N; k++) {
    cin >> S.at(k);
  }
  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 << count + 1 << endl;
}


Error: TLE

Fixed submission:

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

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main() {
  ll N;
  map<string, int> all;
  cin >> N;
  ll cnt = 0;
  for (int i = 0; i < N; i++) {
    string tmp;
    cin >> tmp;
    if (all.end() == all.find(tmp)) {
      cnt++;
      all.insert(make_pair(tmp, 0));
    }
  }
  cout << cnt << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

template <class T> int vector_finder(std::vector<T> vec, T number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance(vec.begin(), itr);
  if (index != vec.size()) { // 発見できたとき
    return 1;
  } else { // 発見できなかったとき
    return 0;
  }
}

int main() {
  ll N;
  // ll S[300000];
  vector<string> all;
  cin >> N;
  ll cnt = 0;
  for (int i = 0; i < N; i++) {
    string tmp;
    cin >> tmp;
    if (!vector_finder(all, tmp)) {
      cnt++;
      all.push_back(tmp);
    }
  }
  cout << cnt << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int64_t N, ans;
  cin >> N;
  ans = N;
  map<string, bool> v;
  for (int64_t i = 0; i < N; i++) {
    string s;
    cin >> s;
    if (v.count(s)) {
      ans--;
    } else {
      v[s] = true;
    }
  }
  cout << ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int64_t N, ans;
  cin >> N;
  ans = N;
  vector<string> S(N);
  for (int64_t i = 0; i < N; i++) {
    cin >> S[i];
    for (int64_t j = 0; j < i; j++) {
      if (S[i] == S[j]) {
        ans--;
        break;
      }
    }
  }
  cout << ans << 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;
  set<string> S;
  string str_tmp;
  for (int i = 0; i < N; i++) {

    cin >> str_tmp;
    S.insert(str_tmp);
  }
  cout << S.size() << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  int N;
  cin >> N;
  vector<string> data(N);
  for (int i = 0; i < N; i++) {
    cin >> data.at(i);
  }
  int count = 1;
  int count_tmp = 0;
  for (int i = 1; i < N; i++) {
    for (int j = 0; j < i; j++) {
      if (data.at(i) != data.at(j)) {
        count_tmp++;
      }
    }
    if (count_tmp == i)
      count++;
    count_tmp = 0;
  }
  cout << count << 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;
using ll = long long;
using P = pair<int, int>;

int main(void) {
  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());
  cout << S.size() << endl;
}


Error: TLE

Fixed submission:

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

int main() {
  int N;
  cin >> N;
  vector<string> num = {};
  rep(i, N) {
    string S;
    cin >> S;
    bool hantei = true;
    rep(j, num.size()) {
      if (num.at(j) == S)
        hantei = false;
    }
    if (hantei)
      num.push_back(S);
  }

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

#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
using namespace std;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;

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


Error: TLE

Fixed submission:

#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
using namespace std;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;

int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  vector<string> copy;
  int ans = 0;
  rep(i, n) { cin >> s[i]; }
  rep(i, n) {
    bool isExist = false;
    rep(j, copy.size()) {
      if (copy[j] == s[i]) {
        isExist = true;
      }
    }
    if (!isExist) {
      copy.push_back(s[i]);
      ans++;
    }
  }
  cout << ans << 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;
  set<string> st;
  for (int i = 0; i < N; i++) {
    string s;
    cin >> s;
    st.insert(s);
  }

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

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;

// nより前に同じ文字列があるかどうか
int nonsame(string S, vector<string> T) {
  for (int i = 0; i < (int)T.size(); i++) {
    if (S.compare(T[i]) == 0)
      return (0);
  }
  return (1);
}

int main() {
  int N;
  cin >> N;
  vector<string> S(N + 1);
  for (int i = 1; i <= N; i++)
    cin >> S[i];

  vector<string> T(1);
  int count = 0;
  T[0] = S[1];
  for (int i = 2; i <= N; i++) {
    if (nonsame(S[i], T)) {
      // cout<< nonsame(S,T,i) <<endl;
      count++;
      T.push_back(S[i]);
    }
  }

  // for (int i=0;i<(int)T.size();i++)
  //   cout<<"T["<<i<<"]="<<T[i]<<endl;

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

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define rep2(i, m, n) for (int(i) = (m); (i) < (n); (i)++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
int main() {
  ios::sync_with_stdio(false);
  cout.tie(nullptr);
  cin.tie(nullptr);
  int n, c = 0;
  cin >> n;
  cin.ignore();
  string a[n], b[n];
  for (int i = 0; i < n; i++) {
    getline(cin, a[i]);
  }
  sort(a, a + n);
  for (int i = 0; i < n; i++) {
    if (a[i] != a[i + 1])
      c++;
  }
  cout << c;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, c = 0;
  cin >> n;
  string a[n], b[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    for (int j = 0; j < i; j++) {
      if (a[i] == a[j]) {
        c++;
        break;
      }
    }
  }
  cout << n - c;
}
Problem p02701 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <map>
#include <string>

using namespace std;

int main() {
  int i, N;
  string tmp;
  map<string, int> S;

  cin >> N;

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

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

  return 0;
}

Error: -6
munmap_chunk(): invalid pointer


Fixed submission:

#include <iostream>
#include <string>

using namespace std;

int main() {
  int i, j, count = 0, N;
  string *S, tmp;

  cin >> N;

  S = new string[N];

  for (i = 0; i < N; i++) {
    cin >> tmp;
    for (j = 0; j < count; j++) {
      if (S[j] == tmp)
        break;
    }

    if (j == count) {
      S[count] = tmp;
      ++count;
    }
  }

  cout << count << endl;

  delete S;

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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define vll vector<ll>
#define vpll vector<pair<ll, ll>>
ll mx = INT_MAX;
ll mi = INT_MIN;

int main() {
  ll n, i, j, s = 0, p = 0, q;
  cin >> n;
  vector<ll> v(100000, 0);
  set<string> st;
  while (n--) {
    string ss;
    cin >> ss;

    ll sum = 0;

    st.insert(ss);
  }

  cout << st.size();
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define vll vector<ll>
#define vpll vector<pair<ll, ll>>
ll mx = INT_MAX;
ll mi = INT_MIN;

int main() {
  ll n, i, j, s = 0, p = 0, q;
  cin >> n;
  vector<ll> v(100000, 0);
  while (n--) {
    string ss;
    cin >> ss;

    ll sum = 0;

    for (i = 0; i < ss.size(); i++) {
      sum = i * sum + (ss[i] - 'a' + 1) * (i + 3) * (i + 3);
    }
    v[sum]++;
  }
  for (i = 0; i < 100000; i++) {
    if (v[i] > 0)
      s++;
  }
  cout << s;
}
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;
  string Si;
  for (int i = 0; i < N; i++) {
    cin >> Si;
    S.push_back(Si);
  }
  int count = 1;
  sort(S.begin(), S.end());
  for (int i = 1; i < N; i++) {
    if (S[i] != S[i - 1]) {
      count++;
    }
  }
  cout << count << '\\n';
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<string> S;
  string Si;
  for (int i = 0; i < N; i++) {
    cin >> Si;
    if (!(find(S.begin(), S.end(), Si) != S.end()))
      S.push_back(Si);
  }
  cout << S.size() << '\\n';
  return 0;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int N;
  cin >> N;
  vector<string> vec(N);
  int count = 0;
  for (int i = 0; i < N; i++) {
    cin >> vec[i];
  }
  sort(vec.begin(), vec.end());
  vec.erase(unique(vec.begin(), vec.end()), vec.end());
  count = (int)vec.size();
  cout << count << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int N;
  cin >> N;
  vector<string> vec;
  int count = 0;
  for (int i = 0; i < N; i++) {
    string s;
    cin >> s;
    auto result = find(vec.begin(), vec.end(), s);
    if (result == vec.end()) {
      vec.push_back(s);
      count++;
    }
  }
  cout << count << endl;
  return 0;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <string>
#include <vector>

using namespace std;

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

  list<string> str;
  string input;
  int n;
  cin >> n;
  while (n--) {

    cin >> input;
    str.push_back(input);
  }
  str.sort();
  str.unique();

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

  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <string>
#include <vector>

using namespace std;

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

  vector<string> str;
  string input;
  int c = 0;
  int n;
  cin >> n;
  bool flag = false;
  while (n--) {

    cin >> input;
    flag = true;
    for (int i = 0; i < c; i++) {
      if (str[i] == input) {
        flag = false;
        break;
      }
    }
    if (flag) {
      c++;
      str.push_back(input);
    } else
      flag = true;
  }

  cout << c << endl;

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

#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;

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

  return 0;
}

Error: -11

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 ans = N;
  for (int i = 0; i < N; i++) {
    /*if (s[i] == "")
    {
        continue;
    }*/

    for (int j = i + 1; j < N; j++) {
      /*if (s[j] == "")
      {
          continue;
      }*/
      if (s[i] == s[j]) {
        ans--;
        s.erase(s.begin() + j);
        i--;

        // s[zj] = "";
      }
    }
  }

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

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

int ans = 1;

int main(void) {
  // input
  int n;
  cin >> n;
  set<string> st;
  for (int i = 0; i < n; i++) {
    string tmp;
    cin >> tmp;
    st.insert(tmp);
  }
  // output
  cout << st.size() << endl;

  return 0;
}

Error: TLE

Fixed submission:

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

int ans = 1;

int main(void) {
  // input
  int n;
  cin >> n;
  vector<string> s(n);
  for (int i = 0; i < n; i++)
    cin >> s[i];
  sort(s.begin(), s.end());

  // calculate
  int count = 0;
  int i = 0, j = 1;
  while (i != n - 1) {
    for (j = i + 1; j < n; ++j) {
      if (s[i] != s[j]) {
        ans++;
        i = j;
        break;
      }
    }
    if (i == 0)
      break;
  }
  // output
  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++)
#define RREP(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
// const ll INF = 1LL << 60;
// const int INF = 1001001001;

int main(void) {
  int n;
  cin >> n;
  set<string> s;
  REP(i, n) {
    string S;
    cin >> S;
    s.insert(S);
  }
  cout << s.size();

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
// const ll INF = 1LL << 60;
// const int INF = 1001001001;

int main(void) {
  int n;
  cin >> n;
  vector<string> v;
  REP(i, n) {
    string s;
    cin >> s;
    bool flag = true;
    REP(j, v.size()) {
      if (v[j] == s) {
        flag = false;
        break;
      }
    }
    if (flag)
      v.push_back(s);
  }
  cout << v.size();

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

#include <algorithm>
#include <bitset>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<string> s;
  for (int i = 0; i < n; i++) {
    string ns;
    cin >> ns;
    s.push_back(ns);
  }

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

  // for(int i=0;i<n;i++) cout << s.at(i) << endl;

  int counter = 1;
  for (int i = 1; i < n; i++) {
    if (s.at(i - 1) != s.at(i))
      counter++;
  }

  cout << counter << endl;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
int main() {
  int n;
  cin >> n;
  int counter = 0;
  if (n == 1) {
    cout << 1 << endl;
    return 0;
  }
  string si;
  cin >> si;
  vector<string> s;
  s.push_back(si);
  for (int i = 0; i < n; i++) {
    string ns;
    cin >> ns;
    int neo = 1;
    for (int j = 0; j < s.size(); j++) {
      if (ns == s.at(j)) {
        neo = 0;
        break;
      }
    }
    if (neo) {
      counter++;
      s.push_back(ns);
    }
  }
  cout << counter << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int m = 0;
  int c = 0;
  vector<string> s(n);
  for (int i = 0; i < n; i++) {
    cin >> s.at(i);
  }

  sort(s.begin(), s.end());
  s.push_back(" ");
  for (int i = 0; i < n; i++) {
    if (s.at(i) != s.at(i + 1)) {
      c++;
    }
  }
  cout << c << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int m = 0;
  int c = 0;
  vector<string> s(n);
  for (int i = 0; i < n; i++) {
    cin >> s.at(i);
  }
  for (int i = 0; i < n; i++) {
    c = 0;
    for (int j = 0; j < i; j++) {
      if (s.at(i) == s.at(j)) {
        c = 1;
        break;
      }
    }
    if (c != 1) {
      m++;
    }
  }
  cout << m << endl;
}
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];
  sort(s, s + n);
  int ans = 1, c = 1;
  for (int i = 0; i < n - 1; i++) {
    if (s[i] == s[i + 1])
      c++;
    else {
      ans++;
      c = 1;
    }
  }
  cout << ans;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k = 0;
  cin >> n;
  string s[n], str[n];
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    for (int j = i - 1; j >= 0; j--) {
      if (s[i] == s[j]) {
        k++;
        break;
      }
    }
  }
  cout << n - k;

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

#include <bits/stdc++.h>

using namespace std;

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

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

  int count = 1;
  for (int j = 1; j < n; j++) {
    count++;
    if (s.at(j) == s.at(j - 1))
      count--;
  }
  cout << count << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

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

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

  int count = 1;
  for (int j = 1; j < n; j++) {
    for (int k = 0; k < j; k++) {
      if (s.at(j) == s.at(k))
        break;
      if (k == j - 1)
        count++;
    }
  }
  cout << count << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

  set<string> str;

  for (int i = 0; i < N; i++) {
    string temp;
    cin >> temp;
    str.insert(temp);
  }
  cout << str.size() << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  int N;
  cin >> N;
  string prize[200010];
  prize[0] == " ";
  for (int i = 1; i <= N; i++) {
    cin >> prize[i];
  }

  int flag = 1, count = 0;

  for (int i = 1; i <= N; i++) {
    for (int j = i - 1; j >= 0; j--) {
      if (prize[i] == prize[j])
        flag = 0;
    }
    if (flag == 1)
      count++;
    flag = 1;
  }

  cout << count << 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;
// using ll = long long;
// using P = pair<int, int>;

int main() {
  int n;
  cin >> n;
  map<string, int> a;
  int ans = 0;
  rep(i, n) {
    string s;
    cin >> s;
    a[s] = 1;
  }
  cout << a.size() << 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;
// using ll = long long;
// using P = pair<int, int>;

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

  rep(i, n) {
    string s;
    cin >> s;
    int flag = 1;
    rep(j, a.size()) {
      if (a[j] == s)
        flag = 0;
    }
    a.push_back(s);
    ans += flag;
  }
  cout << ans << endl;
  return 0;
}
Problem p02701 (C++) — buggy submission, verdict: Runtime Error

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

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  int count = 1;

  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]) {
      count++;
    }
  }

  cout << count << endl;
  return 0;
}

Error: -11

Fixed submission:

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

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  int count = 1;

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

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

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

  cout << count << endl;
  return 0;
}