This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define FF first
#define SS second
#define all(a) a.begin(), a.end()
#define mod (ll)(1000000007)
ll n, k;
vector<int>A, Ans;
void pre(){
A.clear(), Ans.clear();
A.resize(n+1), Ans.resize(n+1);
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
cin>>n>>k;
pre();
for(int i=1;i<=n;i++){
cin>>A[i];
}
vector<int>B=A;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
B[i]=j;
vector<int>Vis(n+1);
int time_=1, cur=1;
while(true){
if(Vis[cur]){
int lim=(k-time_+1)%(time_-Vis[cur]);
for(int f=0;f<=lim;f++){
if(f==lim)
Ans[cur]++;
cur=B[cur];
}
break;
}
Vis[cur]=time_++;
cur=B[cur];
}
}
B[i]=A[i];
}
for(int i=1;i<=n;i++){
cout<<Ans[i]<<endl;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |