QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#359271#8212. Football in Osijekinstallb#WA 2ms12036kbC++201.8kb2024-03-20 15:38:522024-03-20 15:38:52

Judging History

你现在查看的是最新测评结果

  • [2024-03-20 15:38:52]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:12036kb
  • [2024-03-20 15:38:52]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define M 500005
int A[M],deg[M],n,mark[M];
vector<int>edge[M],son[M];
vector<int>B;
int dif[M],Mx[M];
void solve(int rt){
    queue<int>Q,Q2;
    vector<int>P;
    Q.push(rt),mark[rt]=1;
    int s = 0;
    while(!Q.empty()){
        int now=Q.front();Q.pop();
        if(!deg[now])Q2.push(now);s++;
        P.push_back(now);
        for(int &to:edge[now])
            if(!mark[to])Q.push(to),mark[to]=1;
    }
    while(!Q2.empty()){
        int now=Q2.front();Q2.pop();s--;
        int p=-1,mx=0;
        for(int &to:son[now])
            if(Mx[to]>mx)mx=Mx[p=to];
        Mx[now] = mx+1;
        for(int &to:son[now])if(to!=p)
            B.push_back(Mx[to]);
        if((--deg[A[now]]) == 0)Q2.push(A[now]);
    }
    for(int &x:P) if(deg[x]>0){
        for(int &to:son[x])if(deg[to]==0)
            Mx[x] = max(Mx[x],Mx[to]);
    }
    int mx = 0,p = -1;
    for(int &x:P) if(deg[x]>0){
        if(Mx[x] > mx) mx = Mx[p=x];
    }
    for(int &x:P) if(deg[x]>0){
        if(x!=p) B.push_back(Mx[x]);
        else B.push_back(Mx[x]+s);
    }
    dif[s]++;
    dif[s + mx + 1]--;
}
int Ans[M];
int main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        scanf("%d",&A[i]),deg[A[i]]++;
        son[A[i]].push_back(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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 9992kb

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: 2ms
memory: 9932kb

input:

1
1

output:

0 

result:

ok 1 number(s): "0"

Test #3:

score: 0
Accepted
time: 2ms
memory: 12032kb

input:

2
2 2

output:

0 0 

result:

ok 2 number(s): "0 0"

Test #4:

score: -100
Wrong Answer
time: 2ms
memory: 12036kb

input:

10
4 7 2 8 4 3 4 9 7 3

output:

1 1 1 0 0 0 0 1 2 1 

result:

wrong answer 10th numbers differ - expected: '3', found: '1'