QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#470497 | #8212. Football in Osijek | PhantomThreshold# | WA | 0ms | 3868kb | C++20 | 1.3kb | 2024-07-10 14:26:34 | 2024-07-10 14:26:34 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
int n;
cin>>n;
vector<vector<pair<int,int>>> G(n+5);
for(int i=1;i<=n;i++)
{
int x;
cin>>x;
G[i].emplace_back(x,i);
G[x].emplace_back(i,i);
}
vector<int> ans(n+5);
vector<int> vis(n+5),dep(n+5);
int cyc=0,siz=0;
function<void(int,int)>dfs=[&](int u,int pre)
{
// cerr<<"dfs "<<u<<' '<<pre<<endl;
vis[u]=1;
siz++;
for(auto [v,id]:G[u])
{
if(id==pre)continue;
if(not vis[v])
{
dep[v]=dep[u]+1;
dfs(v,id);
}
else if(cyc==0)
{
cyc=dep[u]-dep[v]+1;
}
}
};
int mxsiz=0;
vector<int> sizes;
for(int i=1;i<=n;i++)
{
if(not vis[i])
{
siz=cyc=0;
dep[i]=1;
dfs(i,0);
mxsiz=max(mxsiz,siz);
ans[cyc]++;ans[siz+1]--;
// cerr<<"!! "<<cyc<<' '<<siz<<endl;
sizes.push_back(siz);
}
}
for(int i=1;i<=n;i++)
{
ans[i]+=ans[i-1];
}
for(int i=1;i<=n;i++)
{
if(ans[i]!=0)ans[i]=0;
else ans[i]=1;
}
sort(sizes.begin(),sizes.end(),greater<int>());
int now=0,pre=mxsiz,cnt=-1;
for(auto sz:sizes)
{
now+=sz;cnt++;
for(int i=pre+1;i<=now;i++)
ans[i]=cnt;
pre=now;
}
for(int i=1;i<=n;i++)
{
cout<<ans[i]<<" \n"[i==n];
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3856kb
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: 3628kb
input:
1 1
output:
0
result:
ok 1 number(s): "0"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3512kb
input:
2 2 2
output:
0 0
result:
ok 2 number(s): "0 0"
Test #4:
score: -100
Wrong Answer
time: 0ms
memory: 3868kb
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'