# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
125752 | 2019-07-06T10:07:45 Z | AngusRitossa | 우주 해적 (JOI14_space_pirate) | C++14 | 1686 ms | 91256 KB |
#include <bits/stdc++.h> using namespace std; #ifdef DEBUG #define D(x...) printf(x) #else #define D(x...) #endif typedef long long ll; int n, a[3010], ans[3010]; int canreach[3010][3010], at[3010][3010]; int from[3010][3030], fromsz[3010]; void dfs(int i, int j, int dis = 1) { while (!canreach[i][j]) { canreach[i][j] = dis++; from[i][fromsz[i]++] = j; j = a[j]; } } ll k; int main() { scanf("%d%lld", &n, &k); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); for (int i = 1; i <= n; i++) dfs(i, i); for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { if (canreach[1][i]) { if (i == j) ans[i]++; else if (canreach[j][i]) { ll dis = k-canreach[1][i]+1; dis %= canreach[j][i]; int endpoint = i; if (dis > 0) endpoint = from[j][dis-1]; ans[endpoint]++; } else at[j][canreach[1][i]]++; } else at[1][0]++; } } for (int i = 1; i <= n; i++) { int cyclestart = a[from[i][fromsz[i]-1]]; int loc = -1; for (int j = 0; j < fromsz[i]; j++) { if (from[i][j] == cyclestart) { loc = j; break; } } assert(loc != -1); int sz = fromsz[i]-loc; ll dis2 = k-loc; int dis = dis2%sz + n*sz; for (int j = 0; j <= n; j++) { if (!at[i][j]) continue; ans[from[i][(dis-j)%sz+loc]] += at[i][j]; } } for (int i = 1; i <= n; i++) printf("%d\n", ans[i]); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 1528 KB | Output is correct |
2 | Correct | 3 ms | 1144 KB | Output is correct |
3 | Correct | 3 ms | 1528 KB | Output is correct |
4 | Correct | 3 ms | 1528 KB | Output is correct |
5 | Correct | 3 ms | 1532 KB | Output is correct |
6 | Correct | 3 ms | 1528 KB | Output is correct |
7 | Correct | 3 ms | 1660 KB | Output is correct |
8 | Correct | 3 ms | 1656 KB | Output is correct |
9 | Correct | 3 ms | 1572 KB | Output is correct |
10 | Correct | 3 ms | 1656 KB | Output is correct |
11 | Correct | 3 ms | 1528 KB | Output is correct |
12 | Correct | 3 ms | 1192 KB | Output is correct |
13 | Correct | 3 ms | 1528 KB | Output is correct |
14 | Correct | 3 ms | 1528 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 1528 KB | Output is correct |
2 | Correct | 3 ms | 1144 KB | Output is correct |
3 | Correct | 3 ms | 1528 KB | Output is correct |
4 | Correct | 3 ms | 1528 KB | Output is correct |
5 | Correct | 3 ms | 1532 KB | Output is correct |
6 | Correct | 3 ms | 1528 KB | Output is correct |
7 | Correct | 3 ms | 1660 KB | Output is correct |
8 | Correct | 3 ms | 1656 KB | Output is correct |
9 | Correct | 3 ms | 1572 KB | Output is correct |
10 | Correct | 3 ms | 1656 KB | Output is correct |
11 | Correct | 3 ms | 1528 KB | Output is correct |
12 | Correct | 3 ms | 1192 KB | Output is correct |
13 | Correct | 3 ms | 1528 KB | Output is correct |
14 | Correct | 3 ms | 1528 KB | Output is correct |
15 | Correct | 130 ms | 60732 KB | Output is correct |
16 | Correct | 103 ms | 55184 KB | Output is correct |
17 | Correct | 148 ms | 61060 KB | Output is correct |
18 | Correct | 1563 ms | 85488 KB | Output is correct |
19 | Correct | 778 ms | 85112 KB | Output is correct |
20 | Correct | 876 ms | 79332 KB | Output is correct |
21 | Correct | 1220 ms | 91256 KB | Output is correct |
22 | Correct | 492 ms | 81016 KB | Output is correct |
23 | Correct | 1165 ms | 90624 KB | Output is correct |
24 | Correct | 464 ms | 81116 KB | Output is correct |
25 | Correct | 101 ms | 54852 KB | Output is correct |
26 | Correct | 1686 ms | 71336 KB | Output is correct |
27 | Correct | 545 ms | 74488 KB | Output is correct |
28 | Correct | 644 ms | 75000 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Execution timed out | 3 ms | 256 KB | Time limit exceeded (wall clock) |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 1528 KB | Output is correct |
2 | Correct | 3 ms | 1144 KB | Output is correct |
3 | Correct | 3 ms | 1528 KB | Output is correct |
4 | Correct | 3 ms | 1528 KB | Output is correct |
5 | Correct | 3 ms | 1532 KB | Output is correct |
6 | Correct | 3 ms | 1528 KB | Output is correct |
7 | Correct | 3 ms | 1660 KB | Output is correct |
8 | Correct | 3 ms | 1656 KB | Output is correct |
9 | Correct | 3 ms | 1572 KB | Output is correct |
10 | Correct | 3 ms | 1656 KB | Output is correct |
11 | Correct | 3 ms | 1528 KB | Output is correct |
12 | Correct | 3 ms | 1192 KB | Output is correct |
13 | Correct | 3 ms | 1528 KB | Output is correct |
14 | Correct | 3 ms | 1528 KB | Output is correct |
15 | Correct | 130 ms | 60732 KB | Output is correct |
16 | Correct | 103 ms | 55184 KB | Output is correct |
17 | Correct | 148 ms | 61060 KB | Output is correct |
18 | Correct | 1563 ms | 85488 KB | Output is correct |
19 | Correct | 778 ms | 85112 KB | Output is correct |
20 | Correct | 876 ms | 79332 KB | Output is correct |
21 | Correct | 1220 ms | 91256 KB | Output is correct |
22 | Correct | 492 ms | 81016 KB | Output is correct |
23 | Correct | 1165 ms | 90624 KB | Output is correct |
24 | Correct | 464 ms | 81116 KB | Output is correct |
25 | Correct | 101 ms | 54852 KB | Output is correct |
26 | Correct | 1686 ms | 71336 KB | Output is correct |
27 | Correct | 545 ms | 74488 KB | Output is correct |
28 | Correct | 644 ms | 75000 KB | Output is correct |
29 | Execution timed out | 3 ms | 256 KB | Time limit exceeded (wall clock) |
30 | Halted | 0 ms | 0 KB | - |