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

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<ll> vll;

typedef pair<int, int> pii;

typedef queue<int> qi;
typedef queue<string> qs;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = (a); i <= (b); i++)
#define Rep(i, n) for (int i = n; i >= 0; i--)

#define all(v) v.begin(), v.end()
// sort( all(v) )　などと使える

int a[200010];
int cnt[200010];

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

  a[1] = 0;
  repp(i, 2, n) { cin >> a[i]; }

  repp(i, 2, n) cnt[a[i]]++;

  repp(i, 1, n) cout << cnt[i] << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<ll> vll;

typedef pair<int, int> pii;

typedef queue<int> qi;
typedef queue<string> qs;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = (a); i <= (b); i++)
#define Rep(i, n) for (int i = n; i >= 0; i--)

#define all(v) v.begin(), v.end()
// sort( all(v) )　などと使える

int main() {
  int n;
  cin >> n;
  vi a(n);
  vi cnt(n, 0);

  a[1] = 0;
  repp(i, 2, n) { cin >> a[i]; }

  repp(i, 2, n) cnt[a[i]]++;

  repp(i, 1, n) cout << cnt[i] << endl;
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define erep(i, n) for (int i = 0; i <= (n); i++)
#define erep1(i, n) for (int i = 1; i <= (n); i++)
using namespace std;
using ll = long long;
int main() {
  int N;
  cin >> N;
  int n = N + 1;
  vector<int> a(n);
  for (int i = 2; i <= N; i++) {
    cin >> a[i];
  }
  vector<int> d(n);
  for (int i = 2; i <= N; i++) {
    ++d[a[i]];
  }
  erep1(i, N) cout << d[i] << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define erep(i, n) for (int i = 0; i <= (n); i++)
#define erep1(i, n) for (int i = 1; i <= (n); i++)
using namespace std;
using ll = long long;
int main() {
  int N;
  cin >> N;
  int n = n + 1;
  vector<int> a(n);
  for (int i = 2; i <= N; i++) {
    cin >> a[i];
  }
  vector<int> d(n);
  for (int i = 2; i <= N; i++) {
    ++d[a[i]];
  }
  erep1(i, N) cout << d[i] << endl;
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using pii = pair<int, int>;

#define ff first
#define ss second
#define pb push_back
#define sz size()
#define mp make_pair

const int N = 2e5 + 5;
const int MOD = 1e9 + 7;

int ans[N];

int main() {
  int n, x;
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    cin >> x;
    ans[x]++;
  }
  for (int i = 1; i <= n; i++)
    printf("%d\\n", ans[i]);
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using pii = pair<int, int>;

#define ff first
#define ss second
#define pb push_back
#define sz size()
#define mp make_pair

const int N = 1e5 + 5;
const int MOD = 1e9 + 7;

int ans[N];

int main() {
  int n, x;
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    cin >> x;
    ans[x]++;
  }
  for (int i = 1; i <= n; i++)
    printf("%d\\n", ans[i]);
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded


#include <iostream>
using namespace std;

int main() {
  int n, a, c = 1, t = 0, cnt = 0;

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

  for (int i = 0; i < n - 1; i++) {
    cin >> a;

    if (a != c) {
      t = a - 1;
      c = a;
    }
    ans[t] += 1;
  }

  for (int i = 0; i < n; i++) {
    cout << ans[i] << endl;
  }
}

Error: TLE

Fixed submission:


#include <iostream>
using namespace std;

int main() {
  int n, a;

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

  for (int i = 0; i < n - 1; i++) {
    cin >> a;

    for (int j = 1; j < n; j++) {
      if (a == j) {
        ans[j - 1] += 1;
      }
    }
  }

  for (int i = 0; i < n; i++) {
    cout << ans[i] << endl;
  }
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h> // g++ -std=c++14 -o a a.cpp

using namespace std;

typedef pair<int, int> P;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repto(i, n) for (int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;

int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

__attribute__((constructor)) void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int cnt[200001] = {0};

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

  for (int i = 2; i <= N; i++) {
    int Ai;
    cin >> Ai;
    cnt[Ai]++;
  }

  for (int i = 1; i <= N; i++) {
    cout << cnt[i] << endl;
  }
}


Error: 0

Fixed submission:

#include <bits/stdc++.h> // g++ -std=c++14 -o a a.cpp

using namespace std;

typedef pair<int, int> P;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repto(i, n) for (int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;

int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

__attribute__((constructor)) void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int cnt[20001] = {0};

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

  for (int i = 2; i <= N; i++) {
    int Ai;
    cin >> Ai;
    cnt[Ai]++;
  }

  for (int i = 1; i <= N; i++) {
    cout << cnt[i] << endl;
  }
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;

int main() {
  int n;
  cin >> n;
  int num[n - 1];

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

  int buka[n] = {};
  for (int i = 0; i < n - 1; i++) {
    buka[num[i] - 1] = buka[num[i] - 1] + 1;
  }

  for (int i = 0; i < n; i++) {
    cout << buka[i] << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  int n;
  cin >> n;
  int num[n - 1];

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

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

  for (int i = 0; i < n; i++) {
    cout << buka[i] << endl;
  }

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

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

int main() {
  int n;
  cin >> n;
  vector<int> A(n - 1);
  for (int i = 0; i < n - 1; i++) {
    cin >> A.at(i);
  }
  vector<int> B(n, 0);
  for (int i = 0; i < n - 1; i++) {
    B.at(A.at(i) - 1)++;
  }
  for (int i = 0; i < n; i++) {
    cout << B.at(i) << endl;
  }
}


Error: -6
terminate called after throwing an instance of 'std::out_of_range'
  what():  vector::_M_range_check: __n (which is 4) >= this->size() (which is 4)


Fixed submission:

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

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

  vector<int> A(N - 1);
  for (int i = 0; i < N - 1; i++) {
    cin >> A.at(i);
  }

  int count = 0;
  for (int i = 1; i < N + 1; i++) {
    if (A.at(N - 1) < i) {
      cout << "0" << endl;
    } else {
      for (int j = 0; j < N - 1; j++) {
        if (j < i) {
          continue;
        } else if (A.at(j) == i) {
          count++;
        }
      }
      cout << count << endl;
    }
  }
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

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

#define MOD 1000000007

int main() {
  int N, s[200001];
  int i;
  for (i = 0; i < 200001; i++) {
    s[i] = 0;
  }
  cin >> N;
  for (i = 1; i < N; i++) {
    int A;
    cin >> A;
    s[A - 1]++;
  }
  for (i = 0; i < N; i++) {
    cout << s[i] << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

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

#define MOD 1000000007

int main() {
  int N, s[100001];
  int i;
  for (i = 0; i < 100001; i++) {
    s[i] = 0;
  }
  cin >> N;
  for (i = 1; i < N; i++) {
    int A;
    cin >> A;
    s[A - 1]++;
  }
  for (i = 0; i < N; i++) {
    cout << s[i] << endl;
  }
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int N;
  cin >> N;
  vector<int> AA(N);
  rep(i, N) { AA.at(i) = 0; }
  rep_s(i, 1, N) {
    int A;
    cin >> A;
    AA.at(A - 1) = AA.at(A - 1) + 1;
  }
  rep(i, N) { cout << AA.at(i) << endl; }
}


Error: -6
terminate called after throwing an instance of 'std::out_of_range'
  what():  vector::_M_range_check: __n (which is 0) >= this->size() (which is 0)


Fixed submission:

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

int main() {
  int N;
  cin >> N;
  vector<int> AA;
  rep(i, N) { AA.at(i) = 0; }
  rep(i, N) {
    int A;
    cin >> A;
    AA.at(A)++;
  }
  rep(i, N) { cout << AA.at(i) << endl; }
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n + 1, 0);
  for (int i = 2; i <= n; i++) {
    cin >> a[i];
  }

  vector<int> joshi(n + 1, 0);
  for (int i = 2; i <= n; i++) {
    joshi[a[i]]++;
  }

  for (int i = 1; i <= n; i++) {
    cout << joshi[i] << endl;
  }
}


Error: 0

Fixed submission:

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n, 0);
  for (int i = 2; i <= n; i++) {
    cin >> a[i];
  }

  vector<int> joshi(n, 0);
  for (int i = 2; i <= n; i++) {
    joshi[a[i]]++;
  }

  for (int i = 1; i <= n; i++) {
    cout << joshi[i] << endl;
  }
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
double pi = acos(-1);
int main() {

  int n;
  cin >> n;
  int f[n + 1];
  memset(f, 0, sizeof f);
  for (int i = 2; i <= n; i++) {
    int a;
    cin >> a;
    if (a != i)
      f[a]++;
  }
  for (int i = 1; i <= n; i++)
    cout << f[i] << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
double pi = acos(-1);

int main() {

  int n;
  cin >> n;
  int f[20005];
  memset(f, 0, sizeof f);
  for (int i = 1; i <= n - 1; i++) {
    int a;
    cin >> a;
    f[a]++;
  }
  for (int i = 1; i <= n; i++)
    cout << f[i] << endl;

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

#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
  int N;
  cin >> N;
  int *a = new int[N];
  memset(a, 0, N * sizeof(int));
  int tmp;
  for (int i = 1; i < N; i++) {
    cin >> tmp;
    a[tmp - 1]++;
  }
  for (int i = 0; i < N; i++) {
    cout << a[i] << endl;
  }
}

Error: TLE

Fixed submission:

#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
  int N;
  cin >> N;
  int *a = new int[N];
  memset(a, N * sizeof(int), 0);
  for (int i = 1; i < N; i++)
    cin >> a[i];
  for (int i = 0; i < N; i++) {
    int cnt = 0;
    for (int j = i + 1; j < N; j++) {
      if (a[j] == i + 1)
        cnt++;
    }
    cout << cnt << endl;
  }
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
// #include <string>
#include <vector>
// #include <cmath>

using namespace std;
int main() {
  int N, M, i, j, k, count = 0;
  string str;

  cin >> N;
  vector<int> A(N - 1), B(N);
  for (i = 0; i < N - 1; ++i)
    cin >> A[i];
  for (i = 0; i < N - 1; ++i) // zenninn
    ++B[A[i] - 1];
  for (j = 0; j < N; ++j)
    cout << B[j] << "\\n";
  return 0;
}

Error: TLE

Fixed submission:

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

using namespace std;

int main() {
  int N, M, i, j, k, count = 0;
  string str;

  cin >> N;
  vector<int> A(N - 1), B(N);
  for (i = 0; i < N - 1; ++i)
    cin >> A[i];
  for (i = 0; i < N - 1; ++i) // zenninn
    for (j = 0; j < N; ++j)   // jousi
    {
      if (A[i] - 1 == j) {
        ++B[j];
        break;
      }
    }
  for (j = 0; j < N; ++j)
    cout << B[j] << "\\n";
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll N;
  cin >> N;

  vector<ll> V;

  ll inp;

  for (ll i = 0; i < N - 1; i++) {
    cin >> inp;
    V.push_back(inp);
  }

  unordered_map<ll, ll> mp;

  for (ll i = 0; i < V.size(); i++) {
    mp[V[i]]++;
  }

  for (ll i = 1; i <= N; i++) {
    cout << mp[i] << endl;
  }
}

Error: TLE

Fixed submission:

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll N;
  cin >> N;

  vector<ll> V;

  ll inp;

  for (ll i = 0; i < N - 1; i++) {
    cin >> inp;
    V.push_back(inp);
  }

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

  ll count = 0;

  for (ll i = 1; i <= N; i++) {
    for (ll j = 0; j < V.size(); j++) {
      if (V[j] == i)
        count++;
    }

    cout << count << endl;
    count = 0;
  }

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

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

int main() {
  int N;
  cin >> N;
  vector<int> bossNumber(N);
  for (int i = 1; i < N; i++) {
    cin >> bossNumber.at(i);
  }
  vector<int> numberOfStuff(N);
  for (int i = 1; i < N; i++) {
    numberOfStuff.at(bossNumber.at(i) - 1)++;
  }
  for (int i = 0; i < N; i++) {
    cout << numberOfStuff.at(i) << endl;
  }
}

Error: TLE

Fixed submission:

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

int main() {
  int N;
  cin >> N;
  vector<int> bossNumber(N);
  for (int i = 1; i < N; i++) {
    cin >> bossNumber.at(i);
  }
  vector<int> numberOfStuff(N);
  for (int i = 0; i < N; i++) {
    for (int j = 1; j < N; j++) {
      if (i == bossNumber.at(j) - 1) {
        numberOfStuff.at(i)++;
      }
    }
  }
  for (int i = 0; i < N; i++) {
    cout << numberOfStuff.at(i) << endl;
  }
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i;
  cin >> n;
  int a[n], b[200005] = {0};
  for (i = 0; i < n - 1; i++) {
    cin >> a[i];
    b[a[i]]++;
  }
  for (i = 0; i < n; i++) {
    cout << b[i + 1] << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i;
  cin >> n;
  int a[n], b[100005] = {0};
  for (i = 0; i < n - 1; i++) {
    cin >> a[i];
    b[a[i]]++;
  }
  for (i = 0; i < n; i++) {
    cout << b[i + 1] << endl;
  }
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
  int N;
  cin >> N;

  vector<int> A(N - 1);
  vector<int> ansA(N);
  for (int i = 0; i < N - 1; i++) {
    cin >> A.at(i);
    ansA.at(A.at(i) - 1) += 1;
  }

  for (int i = 0; i < N; i++) {
    cout << ansA.at(i) << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
  int N;
  cin >> N;

  vector<int> A(N - 1);
  for (int i = 0; i < N - 1; i++) {
    cin >> A.at(i);
  }

  vector<int> ansA(N);
  string s;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N - 1; j++) {
      if (i + 1 == A[j]) {
        ansA[i]++;
      }
    }
    s += to_string(ansA[i]) + "\\n";
  }

  cout << s << endl;

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

#include <iostream>
#include <string>
using namespace std;
int main(void) {
  int a;
  cin >> a;
  int s[a];
  for (int i = 0; i < a - 1; i++) {
    cin >> s[i];
  }

  int t[a];
  for (int i = 0; i < a; i++) {
    t[i] = 0;
  }
  for (int i = 0; i < a - 1; i++) {
    t[s[i] - 1]++;
  }
  for (int i = 0; i < a; i++) {
    cout << t[i] << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>
using namespace std;
int main(void) {
  int a;
  cin >> a;
  int s[a];
  for (int i = 0; i < a - 1; i++) {
    cin >> s[i];
  }

  for (int i = 0; i < a; i++) {
    int n = 0;
    for (int j = 0; j < a - 1; j++) {
      if (s[j] == i + 1) {
        n++;
      }
    }
    cout << n << endl;
  }
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define pi 3.14159265358979323846
using namespace std;
int main() {
  int m;
  cin >> m;
  vector<int> v;
  map<int, int> m1;
  for (int i = 0; i < m - 1; i++) {
    int x;
    cin >> x;
    v.push_back(x);
    m1[x]++;
  }
  for (int i = 1; i <= m; i++) {
    if (m1[i])
      cout << m1[i] << endl;
    else
      cout << "0" << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define pi 3.14159265358979323846
using namespace std;
int main() {
  int m;
  cin >> m;
  vector<int> v;
  for (int i = 0; i < m - 1; i++) {
    int x;
    cin >> x;
    v.push_back(x);
  }
  for (int i = 1; i <= m; i++) {
    cout << count(v.begin(), v.end(), i) << endl;
  }
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
long long N;
long long arr[200001];
int main() {
  cin >> N;
  long long ar[N];
  for (long long i = 1; i < N; i++) {
    cin >> ar[i];
    arr[ar[i]]++;
  }
  for (long long i = 1; i <= N; i++) {
    cout << arr[i] << '\\n';
  }
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
long long N;
long long arr[20001];
int main() {
  cin >> N;
  long long ar[N];
  for (int i = 1; i < N; i++) {
    cin >> ar[i];
    arr[ar[i]]++;
  }
  for (int i = 1; i <= N; i++) {
    cout << arr[i] << '\\n';
  }
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>

using namespace std;

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

  vector<int> A(N);

  for (int i = 2; i <= N; ++i) {
    cin >> Ai;
    ++A[Ai - 1];
  }

  for (int i = 0; i < N; ++i) {
    cout << A[i] << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

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

using namespace std;

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

  vector<int> A(N);

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

  for (int i = 0; i < N; ++i) {
    cout << count_if(A.begin(), A.end(), [i](int x) { return x == i + 1; })
         << endl;
  }

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

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

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

  vector<int> vec(N);
  vec.at(0) = 0;
  for (int i = 1; i < N; i++) {
    cin >> vec.at(i); // 上司を代入
  }

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

  vector<int> Me(N, 0); // 自分が上司の回数

  int k = 1;
  for (int j = 0; j < N; j++) {
    if (k == vec.at(j)) {
      Me.at(k - 1)++;
    }
    if (k < vec.at(j)) {

      k++;
      if (k = vec.at(j)) {
        Me.at(k - 1)++;
      }
    }
  }

  for (int p = 0; p < N; p++) {
    cout << Me.at(p) << endl;
  }
}

Error: TLE

Fixed submission:

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

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

  vector<int> vec(N);
  vec.at(0) = 0;
  for (int i = 1; i < N; i++) {
    cin >> vec.at(i); // 上司を代入
  }

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

  vector<int> Me(N, 0); // 自分が上司の回数

  for (int k = 0; k < N; k++) {
    for (int j = 0; j < N; j++) {
      if (k + 1 < vec.at(j)) {
        continue;
      } else if (k + 1 == vec.at(j)) {
        Me.at(k)++;
      } else if (k + 1 < vec.at(j)) {
        break;
      }
    }
  }
  for (int k = 0; k < N; k++) {
    cout << Me.at(k) << endl;
  }
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1 << 29);

int main() {

  int n;
  cin >> n;
  vector<int> s(n);
  REP(i, n - 1) {
    int x;
    cin >> x;
    s[x - 1]++;
  }

  REP(i, n) cout << s[i] << endl;

  return 0;
}

Error: -6
double free or corruption (out)


Fixed submission:

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1 << 29);

int main() {

  int n;
  cin >> n;
  vector<int> a(n - 1);
  REP(i, n - 1) cin >> a[i];

  vector<int> s(n);

  REP(i, n) { s[a[i] - 1]++; }

  REP(i, n) cout << s[i] << endl;

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

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

int main() {
  // 　数値の定義
  int N; // 人数
  cin >> N;

  int num[N];  // 上司番号{0,1,1,2,2}
  int buka[N]; // 部下の数{2,2,0,0,0}

  for (int i = 0; i < N; i++) { // 部下の数をループ
    buka[i] = 0;
    if (i > 0) {
      cin >> num[i];
      buka[num[i] - 1]++;
    }
  }

  // 判定
  for (int i = 0; i < N; i++) {
    cout << buka[i] << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  // 　数値の定義
  int N; // 人数
  cin >> N;

  int num[N];  // 上司番号{0,1,1,2,2}
  int buka[N]; // 部下の数{2,2,0,0,0}

  for (int i = 0; i < N; i++) { // 部下の数をループ
    buka[i] = 0;
    if (i > 0) {
      cin >> num[i];
      for (int j = 0; j < N; j++) { // 上司の数をループ
        // cout << "num[i] = " << num[i] << "   "<< "j+1 = " << j+1 << endl;
        if (num[i] == j + 1) {
          // cout << "--> correct" << endl;
          buka[j]++;
          break;
        }
      }
    }
  }

  // 判定
  for (int i = 0; i < N; i++) {
    cout << buka[i] << endl;
  }

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

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

int main() {
  int N;
  cin >> N;
  vector<int> buka(N);
  vector<int> joshi(N);
  for (int i = 1; i < N; i++) {
    cin >> joshi.at(i);
    buka.at(joshi.at(i) - 1)++;
  }
  for (int i = 0; i < N; i++)
    cout << buka.at(i) << endl;
}


Error: TLE

Fixed submission:

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

int buka(vector<int> &joshi, int x, int N) {
  if (x == N)
    return 0;
  int S = 0;
  for (int i = x + 1; i < N + 1; i++)
    if (x == joshi.at(i))
      S++;
  return S;
}

int main() {
  int N;
  cin >> N;
  vector<int> joshi(N + 1);
  for (int i = 1; i < N; i++)
    cin >> joshi.at(i + 1);

  for (int i = 1; i < N + 1; i++)
    cout << buka(joshi, i, N) << endl;
}