QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#359166 | #8212. Football in Osijek | installb# | WA | 1ms | 9872kb | C++20 | 1.2kb | 2024-03-20 14:06:34 | 2024-03-20 14:06:35 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define M 500005
int A[M],deg[M],n,mark[M];
vector<int>edge[M];
vector<int>B;
int dif[M];
void solve(int rt){
queue<int>Q,Q2;
Q.push(rt),mark[rt]=1;
int s = 0;
while(!Q.empty()){
int now=Q.front();Q.pop();
s++;
if(!deg[now])Q2.push(now);
for(int &to:edge[now])
if(!mark[to])Q.push(to),mark[to]=1;
}
int t = 0;
while(!Q2.empty()){
int now=Q2.front();Q2.pop();
t++;
if((--deg[A[now]]) == 0)Q2.push(A[now]);
}
dif[s-t]++;
dif[s+1]--;
B.push_back(s);
}
int Ans[M];
int main(){
cin>>n;
for(int i=1;i<=n;i++){
scanf("%d",&A[i]),deg[A[i]]++;
edge[i].push_back(A[i]);
edge[A[i]].push_back(i);
}
for(int i=1;i<=n;i++)if(!mark[i])solve(i);
for(int i=1;i<=n;i++)dif[i]+=dif[i-1];
sort(B.begin(),B.end());
reverse(B.begin(),B.end());
int s = B[0];
fill(Ans+1,Ans+1+n,-1);
for(int i=1;i<B.size();i++){
for(int j=s+1;j<=s+B[i];j++)Ans[j]=i;
s += B[i];
}
for(int i=1;i<=n;i++)
if(Ans[i]==-1) printf("%d ",dif[i]>0?0:1);
else printf("%d ",Ans[i]);
puts("");
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 8200kb
input:
5 2 3 1 3 5
output:
0 1 0 0 1
result:
ok 5 number(s): "0 1 0 0 1"
Test #2:
score: 0
Accepted
time: 1ms
memory: 7884kb
input:
1 1
output:
0
result:
ok 1 number(s): "0"
Test #3:
score: 0
Accepted
time: 1ms
memory: 7828kb
input:
2 2 2
output:
0 0
result:
ok 2 number(s): "0 0"
Test #4:
score: -100
Wrong Answer
time: 1ms
memory: 9872kb
input:
10 4 7 2 8 4 3 4 9 7 3
output:
1 1 1 0 0 0 0 0 0 0
result:
wrong answer 8th numbers differ - expected: '1', found: '0'