# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
52288 | 2018-06-25T08:03:17 Z | 김세빈(#1347) | 우주 해적 (JOI14_space_pirate) | C++11 | 2000 ms | 71884 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,r; 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,x1; 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]; } int cnt = 0; ans[1] ++; for(i=2;i<=n;i++){ if(K[i][1]){ ll r = k % (K[i][1] + 1); if(r == 0) ans[1] ++; else if(r == 1) ans[i] ++; else ans[run(i, r-1)] ++; } else ans[run(i, k-1)] ++; } for(i=2;i<=n;i++) if(K[1][i]){ x1 = K[1][i]; for(j=1;j<=n;j++){ if(i == j) ans[i] ++; else{ if(K[j][i]){ r = (k - x1) % (K[j][i] + 1); if(r == 0) ans[i] ++; else if(r == 1) ans[j] ++; else ans[run(j, r-1)] ++; } else ans[run(j, k-1-x1)] ++; } } cnt ++; } ans[run(1,k)] += n * (n - cnt - 1); for(i=1;i<=n;i++) printf("%d\n",ans[i]); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | 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 | 1436 KB | Output is correct |
5 | Correct | 3 ms | 1436 KB | Output is correct |
6 | Correct | 3 ms | 1436 KB | Output is correct |
7 | Correct | 3 ms | 1436 KB | Output is correct |
8 | Correct | 4 ms | 1444 KB | Output is correct |
9 | Correct | 3 ms | 1444 KB | Output is correct |
10 | Correct | 3 ms | 1444 KB | Output is correct |
11 | Correct | 2 ms | 1444 KB | Output is correct |
12 | Correct | 3 ms | 1444 KB | Output is correct |
13 | Correct | 3 ms | 1444 KB | Output is correct |
14 | Correct | 3 ms | 1444 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | 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 | 1436 KB | Output is correct |
5 | Correct | 3 ms | 1436 KB | Output is correct |
6 | Correct | 3 ms | 1436 KB | Output is correct |
7 | Correct | 3 ms | 1436 KB | Output is correct |
8 | Correct | 4 ms | 1444 KB | Output is correct |
9 | Correct | 3 ms | 1444 KB | Output is correct |
10 | Correct | 3 ms | 1444 KB | Output is correct |
11 | Correct | 2 ms | 1444 KB | Output is correct |
12 | Correct | 3 ms | 1444 KB | Output is correct |
13 | Correct | 3 ms | 1444 KB | Output is correct |
14 | Correct | 3 ms | 1444 KB | Output is correct |
15 | Correct | 93 ms | 48976 KB | Output is correct |
16 | Correct | 46 ms | 48976 KB | Output is correct |
17 | Correct | 119 ms | 49372 KB | Output is correct |
18 | Execution timed out | 2074 ms | 71884 KB | Time limit exceeded |
19 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 71884 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | 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 | 1436 KB | Output is correct |
5 | Correct | 3 ms | 1436 KB | Output is correct |
6 | Correct | 3 ms | 1436 KB | Output is correct |
7 | Correct | 3 ms | 1436 KB | Output is correct |
8 | Correct | 4 ms | 1444 KB | Output is correct |
9 | Correct | 3 ms | 1444 KB | Output is correct |
10 | Correct | 3 ms | 1444 KB | Output is correct |
11 | Correct | 2 ms | 1444 KB | Output is correct |
12 | Correct | 3 ms | 1444 KB | Output is correct |
13 | Correct | 3 ms | 1444 KB | Output is correct |
14 | Correct | 3 ms | 1444 KB | Output is correct |
15 | Correct | 93 ms | 48976 KB | Output is correct |
16 | Correct | 46 ms | 48976 KB | Output is correct |
17 | Correct | 119 ms | 49372 KB | Output is correct |
18 | Execution timed out | 2074 ms | 71884 KB | Time limit exceeded |
19 | Halted | 0 ms | 0 KB | - |