Submission #580115

# Submission time Handle Problem Language Result Execution time Memory
580115 2022-06-20T15:38:43 Z vqpahmad Birokracija (COCI18_birokracija) C++14
60 / 100
1000 ms 4224 KB
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
#define all(a) a.begin(),a.end()
#define mod (ll)(10000007)
using namespace std;
const int mx = 1e6 + 15;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    vector<int> a(n);
    vector<ll> freq(n+1);
    a[0]=-1;
    for (int i=1;i<n;i++){
        cin >> a[i];
        a[i]--;
    }
    for (int i=n-1; i>=1;i--){
        freq[i+1]++;
        int cur = a[i];
        int cnt = 1;
        //cout << cur+1 << ' ';
        while (cur!=-1){
            freq[cur]+=++cnt;
            cur = a[cur];
            //cout << cur+1 << ' ';
        }
    }
    freq[0]++;
    freq[1]++;
    // idk why
    for (int i=0;i<n;i++){
        cout << freq[i] << ' ';
    }


}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 328 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 724 KB Output is correct
2 Correct 77 ms 736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 1664 KB Output is correct
2 Correct 333 ms 1736 KB Output is correct
3 Execution timed out 1080 ms 1548 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 46 ms 4172 KB Output is correct
2 Execution timed out 1076 ms 3916 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 46 ms 4224 KB Output is correct
2 Execution timed out 1074 ms 3804 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 40 ms 4172 KB Output is correct
2 Execution timed out 1084 ms 3812 KB Time limit exceeded
3 Halted 0 ms 0 KB -