# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
52284 | 2018-06-25T07:49:11 Z | 김세빈(#1347) | Space Pirate (JOI14_space_pirate) | C++11 | 2000 ms | 71808 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; int K[3030][3030], B[3030][3030]; int R[3030], F[3030], P[101010]; int ans[101010]; int n; ll k; int run(int p,ll d) { if(d <= F[p]) return B[p][d]; if(d == 0) return p; return B[p][(d - F[p]) % R[p] + F[p]]; } int main() { scanf("%d%lld",&n,&k); if(n > 3000){ return 0; } int i,j,t,a,b; for(i=1;i<=n;i++){ scanf("%d",P+i); } for(i=1;i<=n;i++){ for(j=i,t=0;;j=P[j],t++){ if(K[i][j]) break; K[i][j] = t; B[i][t] = j; } R[i] = t-K[i][j]; F[i] = K[i][j]; } ll cnt = 0; for(i=1;i<=n;i++) if(i == 1 || K[1][i]){ for(j=1;j<=n;j++){ a = i, b = j; if(a == b) ans[a] ++; else if(a == 1){ if(K[b][1]){ ll r = k % (K[b][1] + 1); if(r == 0) ans[a] ++; else if(r == 1) ans[b] ++; else ans[run(b, r-1)] ++; } else ans[run(b, k-1)] ++; } else{ if(K[b][a]){ ll r = (k - K[1][a]) % (K[b][a] + 1); if(r == 0) ans[a] ++; else if(r == 1) ans[b] ++; else ans[run(b, r-1)] ++; } else ans[run(b, k-1-K[1][a])] ++; } } cnt ++; } ans[run(1,k)] += n * (n - cnt); for(i=1;i<=n;i++) printf("%d\n",ans[i]); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 1144 KB | Output is correct |
2 | Correct | 3 ms | 1256 KB | Output is correct |
3 | Correct | 3 ms | 1256 KB | Output is correct |
4 | Correct | 4 ms | 1308 KB | Output is correct |
5 | Correct | 4 ms | 1356 KB | Output is correct |
6 | Correct | 3 ms | 1388 KB | Output is correct |
7 | Correct | 4 ms | 1388 KB | Output is correct |
8 | Correct | 4 ms | 1388 KB | Output is correct |
9 | Correct | 3 ms | 1388 KB | Output is correct |
10 | Correct | 3 ms | 1388 KB | Output is correct |
11 | Correct | 3 ms | 1388 KB | Output is correct |
12 | Correct | 3 ms | 1420 KB | Output is correct |
13 | Correct | 3 ms | 1420 KB | Output is correct |
14 | Correct | 3 ms | 1420 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 1144 KB | Output is correct |
2 | Correct | 3 ms | 1256 KB | Output is correct |
3 | Correct | 3 ms | 1256 KB | Output is correct |
4 | Correct | 4 ms | 1308 KB | Output is correct |
5 | Correct | 4 ms | 1356 KB | Output is correct |
6 | Correct | 3 ms | 1388 KB | Output is correct |
7 | Correct | 4 ms | 1388 KB | Output is correct |
8 | Correct | 4 ms | 1388 KB | Output is correct |
9 | Correct | 3 ms | 1388 KB | Output is correct |
10 | Correct | 3 ms | 1388 KB | Output is correct |
11 | Correct | 3 ms | 1388 KB | Output is correct |
12 | Correct | 3 ms | 1420 KB | Output is correct |
13 | Correct | 3 ms | 1420 KB | Output is correct |
14 | Correct | 3 ms | 1420 KB | Output is correct |
15 | Correct | 95 ms | 49068 KB | Output is correct |
16 | Correct | 49 ms | 49068 KB | Output is correct |
17 | Correct | 121 ms | 49356 KB | Output is correct |
18 | Execution timed out | 2073 ms | 71808 KB | Time limit exceeded |
19 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 71808 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 1144 KB | Output is correct |
2 | Correct | 3 ms | 1256 KB | Output is correct |
3 | Correct | 3 ms | 1256 KB | Output is correct |
4 | Correct | 4 ms | 1308 KB | Output is correct |
5 | Correct | 4 ms | 1356 KB | Output is correct |
6 | Correct | 3 ms | 1388 KB | Output is correct |
7 | Correct | 4 ms | 1388 KB | Output is correct |
8 | Correct | 4 ms | 1388 KB | Output is correct |
9 | Correct | 3 ms | 1388 KB | Output is correct |
10 | Correct | 3 ms | 1388 KB | Output is correct |
11 | Correct | 3 ms | 1388 KB | Output is correct |
12 | Correct | 3 ms | 1420 KB | Output is correct |
13 | Correct | 3 ms | 1420 KB | Output is correct |
14 | Correct | 3 ms | 1420 KB | Output is correct |
15 | Correct | 95 ms | 49068 KB | Output is correct |
16 | Correct | 49 ms | 49068 KB | Output is correct |
17 | Correct | 121 ms | 49356 KB | Output is correct |
18 | Execution timed out | 2073 ms | 71808 KB | Time limit exceeded |
19 | Halted | 0 ms | 0 KB | - |