# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
442401 | koioi.org-koosaga | Counterspells (CPSPC17_counterspells) | C++17 | 1084 ms | 3780 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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);
}
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |