Submission #580097

#TimeUsernameProblemLanguageResultExecution timeMemory
580097ammar124Birokracija (COCI18_birokracija)C++14
60 / 100
1088 ms4172 KiB
#include <bits/stdc++.h> #define endl '\n' #define ll long long using namespace std; int const maxin = 1e5+6; int main() { ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); int a; cin>>a; int arr[a+1]; int price[a+1] = {0}; arr[1] = 0; arr[0] = 0; for(int i=2;i<a+1;i++) { cin>>arr[i]; } int arr2[a+1]; for(int i=0;i<a+1;i++) { arr2[i] = arr[i]; } sort(arr,arr+a); for(int i=a;i>=1;i--) { bool flag = true ; int indx = arr2[i]; int cnt = 2; price[i]+=1; while(flag == true) { if(indx == 0) flag = false ; else { price[indx]+=cnt; cnt++; indx = arr2[indx]; } } } for(int i=1;i<a+1;i++) { cout<<price[i]<<" "; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...