# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
442401 | 2021-07-07T17:03:13 Z | koioi.org-koosaga | Counterspells (CPSPC17_counterspells) | C++17 | 1000 ms | 3780 KB |
#include <bits/stdc++.h> #define sz(v) ((int)(v).size()) #define all(v) (v).begin(), (v).end() using namespace std; using lint = long long; using pi = pair<int, int>; const int MAXN = 200005; const int mod = 1e9 + 7; int n, p[MAXN], dep[MAXN]; int val[MAXN], cnt[MAXN]; int main(){ scanf("%d",&n); p[0] = -1; for(int i = 1; i <= n; i++){ scanf("%d",&p[i]); dep[i] = dep[p[i]] + 1; if(dep[i] % 2) cnt[i]++; } for(int i = 1; i <= n; i++){ val[i] = dep[i] % 2; int ans = 0; if(dep[i] % 2){ int j = i; while(~p[j] && cnt[p[j]] == 0){ j = p[j]; cnt[j]++; ans++; } if(~p[j]) cnt[p[j]]++; } else{ int j = i; while(~p[j] && cnt[p[j]] == 1){ j = p[j]; cnt[j]--; ans++; } if(~p[j]) cnt[p[j]]--; } printf("%d\n", ans); } }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 332 KB | Output is correct |
2 | Correct | 1 ms | 204 KB | Output is correct |
3 | Correct | 1 ms | 204 KB | Output is correct |
4 | Correct | 1 ms | 332 KB | Output is correct |
5 | Correct | 1 ms | 204 KB | Output is correct |
6 | Correct | 1 ms | 204 KB | Output is correct |
7 | Correct | 1 ms | 204 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 332 KB | Output is correct |
2 | Correct | 1 ms | 204 KB | Output is correct |
3 | Correct | 1 ms | 204 KB | Output is correct |
4 | Correct | 1 ms | 332 KB | Output is correct |
5 | Correct | 1 ms | 204 KB | Output is correct |
6 | Correct | 1 ms | 204 KB | Output is correct |
7 | Correct | 1 ms | 204 KB | Output is correct |
8 | Correct | 4 ms | 460 KB | Output is correct |
9 | Correct | 90 ms | 440 KB | Output is correct |
10 | Correct | 2 ms | 332 KB | Output is correct |
11 | Correct | 2 ms | 460 KB | Output is correct |
12 | Correct | 2 ms | 460 KB | Output is correct |
13 | Correct | 6 ms | 460 KB | Output is correct |
14 | Correct | 16 ms | 452 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 332 KB | Output is correct |
2 | Correct | 1 ms | 204 KB | Output is correct |
3 | Correct | 1 ms | 204 KB | Output is correct |
4 | Correct | 1 ms | 332 KB | Output is correct |
5 | Correct | 1 ms | 204 KB | Output is correct |
6 | Correct | 1 ms | 204 KB | Output is correct |
7 | Correct | 1 ms | 204 KB | Output is correct |
8 | Correct | 4 ms | 460 KB | Output is correct |
9 | Correct | 90 ms | 440 KB | Output is correct |
10 | Correct | 2 ms | 332 KB | Output is correct |
11 | Correct | 2 ms | 460 KB | Output is correct |
12 | Correct | 2 ms | 460 KB | Output is correct |
13 | Correct | 6 ms | 460 KB | Output is correct |
14 | Correct | 16 ms | 452 KB | Output is correct |
15 | Correct | 25 ms | 1900 KB | Output is correct |
16 | Execution timed out | 1084 ms | 1696 KB | Time limit exceeded |
17 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 55 ms | 3780 KB | Output is correct |
2 | Correct | 43 ms | 3608 KB | Output is correct |
3 | Correct | 32 ms | 3144 KB | Output is correct |
4 | Correct | 47 ms | 3736 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 332 KB | Output is correct |
2 | Correct | 1 ms | 204 KB | Output is correct |
3 | Correct | 1 ms | 204 KB | Output is correct |
4 | Correct | 1 ms | 332 KB | Output is correct |
5 | Correct | 1 ms | 204 KB | Output is correct |
6 | Correct | 1 ms | 204 KB | Output is correct |
7 | Correct | 1 ms | 204 KB | Output is correct |
8 | Correct | 4 ms | 460 KB | Output is correct |
9 | Correct | 90 ms | 440 KB | Output is correct |
10 | Correct | 2 ms | 332 KB | Output is correct |
11 | Correct | 2 ms | 460 KB | Output is correct |
12 | Correct | 2 ms | 460 KB | Output is correct |
13 | Correct | 6 ms | 460 KB | Output is correct |
14 | Correct | 16 ms | 452 KB | Output is correct |
15 | Correct | 25 ms | 1900 KB | Output is correct |
16 | Execution timed out | 1084 ms | 1696 KB | Time limit exceeded |
17 | Halted | 0 ms | 0 KB | - |