QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#457758#8838. Jesse's JobPhantomThreshold#WA 1ms5692kbC++201.0kb2024-06-29 13:57:002024-06-29 13:57:03

Judging History

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

  • [2024-06-29 13:57:03]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5692kb
  • [2024-06-29 13:57:00]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
using namespace std;

const int maxn = 1100000;

int n;
int a[maxn],v[maxn];

vector<int>ans;
void mygo(const int x)
{
	v[x]=1;
	ans.push_back(a[x]);
	if(!v[a[x]]) mygo(a[x]);
}
void avemujica(const int x,const int fir)
{
	ans.push_back(x);
	if(a[x]<fir) return;
	avemujica(a[x],fir);
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int Tcase; cin>>Tcase;
	while(Tcase--)
	{
		cin>>n;
		for(int i=1;i<=n;i++)
		{
			cin>>a[i];
			v[i]=0;
		}
		
		vector<int>_; ans.swap(_);
		int res=0;
		if(a[1]==1) res=n, ans.push_back(1);
		else
		{
			mygo(1);
			if((int)ans.size()==n)
			{
				res=n-2;
				ans.clear();
				if(a[1]==2) ans.push_back(1);
				else
				{
					avemujica(1,a[1]);
				}
			}
			else
			{
				res=n;
			}
		}
		cout<<res<<'\n';
		sort(ans.begin(),ans.end());
		cout<<ans.size()<<'\n';
		for(int i=0;i<(int)ans.size();i++) cout<<ans[i]<<" \n"[i==(int)ans.size()-1];
	}
	
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 5456kb

input:

3
2
2 1
4
2 1 4 3
6
3 5 4 2 6 1

output:

0
1
1
4
2
1 2
4
3
1 3 4

result:

ok Correct (3 test cases)

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 5692kb

input:

872
6
1 5 2 6 3 4
6
5 2 1 3 4 6
4
2 1 3 4
6
2 3 1 4 5 6
6
4 5 1 6 2 3
6
6 2 3 1 4 5
5
2 1 3 4 5
6
1 2 6 4 3 5
4
2 1 4 3
6
1 6 4 2 5 3
6
6 1 3 5 4 2
6
2 1 4 5 6 3
6
3 4 1 5 6 2
6
4 1 5 3 2 6
6
5 2 1 6 3 4
6
4 1 6 2 5 3
6
5 1 3 6 2 4
6
6 2 5 4 3 1
6
6 2 5 3 1 4
6
5 2 4 1 3 6
6
6 1 3 2 4 5
6
2 3 4 6 5 ...

output:

6
1
1
6
4
1 3 4 5
4
2
1 2
6
3
1 2 3
6
4
1 3 4 6
6
4
1 4 5 6
5
2
1 2
6
1
1
4
2
1 2
6
1
1
6
3
1 2 6
6
2
1 2
6
2
1 3
6
5
1 2 3 4 5
6
3
1 3 5
6
3
1 2 4
6
3
1 2 5
6
2
1 6
6
5
1 3 4 5 6
6
4
1 3 4 5
6
5
1 2 4 5 6
6
5
1 2 3 4 6
6
5
1 2 3 5 6
6
2
1 4
4
2
1 4
6
2
1 3
6
1
1
6
1
1
6
1
1
4
2
1 5
6
2
1 2
6
5
1 2 ...

result:

wrong answer Participant didn't find permutation (test case 30)