QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#470497#8212. Football in OsijekPhantomThreshold#WA 0ms3868kbC++201.3kb2024-07-10 14:26:342024-07-10 14:26:34

Judging History

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

  • [2024-07-10 14:26:34]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3868kb
  • [2024-07-10 14:26:34]
  • 提交

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'