QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#715375#8212. Football in Osijekucup-team5071#WA 0ms3784kbC++201.2kb2024-11-06 11:40:122024-11-06 11:40:13

Judging History

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

  • [2024-11-06 11:40:13]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3784kb
  • [2024-11-06 11:40:12]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int inf=1e9;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;cin>>n;
    vector<int> vis(n+1);
    vector<int> a(n+1);
    vector<int> cnt(n+1),num(n+1,1),flag(n+1,0);
    for(int i=1;i<=n;i++){
        cin>>a[i];
        cnt[a[i]]++;
    }
    queue<int> qu;;
    for(int i=1;i<=n;i++)if(cnt[i]==0){
        qu.push(i);
    }
    while(!qu.empty()){
        int x=qu.front();qu.pop();
        num[a[x]]+=num[x];
        vis[x]=1;
        if(--cnt[a[x]]==0)qu.push(a[x]);
    }
    vector<int> all;
    for(int i=1;i<=n;i++)if(!vis[i]){
        int now=a[i],l=1,r=num[i];
        vis[i]=1;
        while(now!=i){
            vis[now]=1;
            l++;r+=num[now];
            now=a[now];
        }
        all.push_back(r);
        for(int j=l;j<=r;j++)flag[j]=1;
    }
    sort(all.begin(),all.end(),greater<int>());
    vector<int> ans(n+1,inf);
    for(int i=0,now=0;i<all.size();i++){
        for(int j=now+1;j<=now+all[i];j++)ans[j]=i;
        now+=all[i];
    }
    for(int i=1;i<=n;i++)if(!flag[i])ans[i]=max(ans[i],1);
    for(int i=1;i<=n;i++)cout<<ans[i]<<" \n"[i==n];
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3784kb

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: 0ms
memory: 3544kb

input:

1
1

output:

0

result:

ok 1 number(s): "0"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3544kb

input:

2
2 2

output:

0 0

result:

ok 2 number(s): "0 0"

Test #4:

score: -100
Wrong Answer
time: 0ms
memory: 3612kb

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'