# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
52279 | 2018-06-25T07:39:07 Z | 윤교준(#1348) | Space Pirate (JOI14_space_pirate) | C++11 | 1448 ms | 66672 KB |
#include <bits/stdc++.h> #define rf(x) (x)=0;while(*p<48)p++;while(47<*p)(x)=((x)<<3)+((x)<<1)+(*p++&15); #define pb push_back #define sz(V) ((int)(V).size()) #define allv(V) ((V).begin()),((V).end()) #define revv(V) reverse(allv(V)) #define sorv(V) sort(allv(V)) #define univ(V) (V).erase(unique(allv(V)),(V).end()) #define upmin(a,b) (a)=min((a),(b)) #define upmax(a,b) (a)=max((a),(b)) using namespace std; typedef long long ll; const int MAXN = 3005; vector<int> CV[MAXN]; vector<int> UV[MAXN]; int UVI[MAXN][MAXN]; int CI[MAXN], CJ[MAXN], Cn; int chki[MAXN]; bitset<MAXN> chk; ll Ans[MAXN]; int A[MAXN]; int N; ll K; int f(int a, int b) { if(CI[UV[1][0]] == CI[a]) { int l = sz(UV[1]) - 1; l += (CJ[a] - CJ[UV[1][0]] + sz(CV[CI[a]])) % sz(CV[CI[a]]); l++; l += sz(UV[b]) - 1; if(CI[UV[b][0]] != CI[a]) { int idx = (K - l + CJ[UV[b][0]]) % sz(CV[CI[UV[b][0]]]); return CV[CI[UV[b][0]]][idx]; } int c = UV[b][0]; int cl = (CJ[a] - CJ[c] + sz(CV[CI[a]])) % sz(CV[CI[a]]); cl++; cl += sz(UV[b]) - 1; int idx = (K - l) % cl; if(idx <= (CJ[a] - CJ[c] + sz(CV[CI[a]])) % sz(CV[CI[a]])) { idx = (CJ[c] + idx) % sz(CV[CI[a]]); return CV[CI[a]][idx]; } idx -= (CJ[a] - CJ[c] + sz(CV[CI[a]])) % sz(CV[CI[a]]); idx--; return UV[b][sz(UV[b])-idx-1]; } if(0 <= UVI[1][a]) { if(0 <= UVI[b][a]) { int l = sz(UV[1]) - sz(UV[a]) + 1; int cl = sz(UV[b]) - sz(UV[a]) + 1; int idx = (K - l) % cl; return UV[b][sz(UV[b])-idx-1]; } int l = sz(UV[1]) - sz(UV[a]) + sz(UV[b]); int c = UV[b][0]; int idx = (K - l + CJ[c]) % sz(CV[CI[c]]); return CV[CI[c]][idx]; } int l = sz(UV[1]) - 1; int c = UV[1][0]; int idx = (K - l + CJ[c]) % sz(CV[CI[c]]); return CV[CI[c]][idx]; } int main() { scanf("%d%lld", &N, &K); for(int i = 1; i <= N; i++) scanf("%d", &A[i]); fill(chki, chki+N+1, -1); for(int i = 1; i <= N; i++) if(!chk[i]) { vector<int> V; int c = 0, cs = -1; for(int idx = i;;) { V.pb(idx); chk[idx] = true; chki[idx] = c++; idx = A[idx]; if(chk[idx]) { cs = chki[idx]; break; } } for(int v : V) chki[v] = -1; if(cs < 0) continue; Cn++; for(int i = cs; i < c; i++) { CV[Cn].pb(V[i]); CI[V[i]] = Cn; CJ[V[i]] = i-cs; } } for(int i = 1; i <= N; i++) if(CI[i]) UV[i].pb(i); for(int i = 1; i <= N; i++) if(UV[i].empty()) { vector<int> V; for(int idx = i;;) { V.pb(idx); idx = A[idx]; if(!UV[idx].empty()) break; } revv(V); for(int v : V) { UV[v] = UV[A[v]]; UV[v].pb(v); } } for(int i = 1; i <= N; i++) { fill(UVI[i], UVI[i]+N+1, -1); for(int j = 0; j < sz(UV[i]); j++) UVI[i][UV[i][j]] = j; } for(int a = 1; a <= N; a++) for(int b = 1; b <= N; b++) Ans[f(a, b)]++; for(int i = 1; i <= N; i++) printf("%lld\n", Ans[i]); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 888 KB | Output is correct |
2 | Correct | 3 ms | 996 KB | Output is correct |
3 | Correct | 3 ms | 1072 KB | Output is correct |
4 | Correct | 3 ms | 1132 KB | Output is correct |
5 | Correct | 3 ms | 1132 KB | Output is correct |
6 | Correct | 3 ms | 1132 KB | Output is correct |
7 | Correct | 3 ms | 1132 KB | Output is correct |
8 | Correct | 3 ms | 1132 KB | Output is correct |
9 | Correct | 3 ms | 1212 KB | Output is correct |
10 | Correct | 3 ms | 1212 KB | Output is correct |
11 | Correct | 4 ms | 1212 KB | Output is correct |
12 | Correct | 4 ms | 1212 KB | Output is correct |
13 | Correct | 4 ms | 1212 KB | Output is correct |
14 | Correct | 3 ms | 1212 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 888 KB | Output is correct |
2 | Correct | 3 ms | 996 KB | Output is correct |
3 | Correct | 3 ms | 1072 KB | Output is correct |
4 | Correct | 3 ms | 1132 KB | Output is correct |
5 | Correct | 3 ms | 1132 KB | Output is correct |
6 | Correct | 3 ms | 1132 KB | Output is correct |
7 | Correct | 3 ms | 1132 KB | Output is correct |
8 | Correct | 3 ms | 1132 KB | Output is correct |
9 | Correct | 3 ms | 1212 KB | Output is correct |
10 | Correct | 3 ms | 1212 KB | Output is correct |
11 | Correct | 4 ms | 1212 KB | Output is correct |
12 | Correct | 4 ms | 1212 KB | Output is correct |
13 | Correct | 4 ms | 1212 KB | Output is correct |
14 | Correct | 3 ms | 1212 KB | Output is correct |
15 | Correct | 251 ms | 37612 KB | Output is correct |
16 | Correct | 204 ms | 37612 KB | Output is correct |
17 | Correct | 226 ms | 37612 KB | Output is correct |
18 | Correct | 450 ms | 37612 KB | Output is correct |
19 | Correct | 305 ms | 37612 KB | Output is correct |
20 | Correct | 480 ms | 45084 KB | Output is correct |
21 | Correct | 1378 ms | 60344 KB | Output is correct |
22 | Correct | 722 ms | 60344 KB | Output is correct |
23 | Correct | 1448 ms | 66672 KB | Output is correct |
24 | Correct | 731 ms | 66672 KB | Output is correct |
25 | Correct | 185 ms | 66672 KB | Output is correct |
26 | Correct | 368 ms | 66672 KB | Output is correct |
27 | Correct | 460 ms | 66672 KB | Output is correct |
28 | Correct | 378 ms | 66672 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 17 ms | 66672 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 888 KB | Output is correct |
2 | Correct | 3 ms | 996 KB | Output is correct |
3 | Correct | 3 ms | 1072 KB | Output is correct |
4 | Correct | 3 ms | 1132 KB | Output is correct |
5 | Correct | 3 ms | 1132 KB | Output is correct |
6 | Correct | 3 ms | 1132 KB | Output is correct |
7 | Correct | 3 ms | 1132 KB | Output is correct |
8 | Correct | 3 ms | 1132 KB | Output is correct |
9 | Correct | 3 ms | 1212 KB | Output is correct |
10 | Correct | 3 ms | 1212 KB | Output is correct |
11 | Correct | 4 ms | 1212 KB | Output is correct |
12 | Correct | 4 ms | 1212 KB | Output is correct |
13 | Correct | 4 ms | 1212 KB | Output is correct |
14 | Correct | 3 ms | 1212 KB | Output is correct |
15 | Correct | 251 ms | 37612 KB | Output is correct |
16 | Correct | 204 ms | 37612 KB | Output is correct |
17 | Correct | 226 ms | 37612 KB | Output is correct |
18 | Correct | 450 ms | 37612 KB | Output is correct |
19 | Correct | 305 ms | 37612 KB | Output is correct |
20 | Correct | 480 ms | 45084 KB | Output is correct |
21 | Correct | 1378 ms | 60344 KB | Output is correct |
22 | Correct | 722 ms | 60344 KB | Output is correct |
23 | Correct | 1448 ms | 66672 KB | Output is correct |
24 | Correct | 731 ms | 66672 KB | Output is correct |
25 | Correct | 185 ms | 66672 KB | Output is correct |
26 | Correct | 368 ms | 66672 KB | Output is correct |
27 | Correct | 460 ms | 66672 KB | Output is correct |
28 | Correct | 378 ms | 66672 KB | Output is correct |
29 | Runtime error | 17 ms | 66672 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
30 | Halted | 0 ms | 0 KB | - |