QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#558900#8835. Goodmanknightofshadow#RE 28ms5584kbC++14522b2024-09-11 19:13:502024-09-11 19:13:50

Judging History

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

  • [2024-09-11 19:13:50]
  • 评测
  • 测评结果:RE
  • 用时:28ms
  • 内存:5584kb
  • [2024-09-11 19:13:50]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll num[202020],f[202020];
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll t,n;
	cin>>t;
	while(t--){
		cin>>n;
		vector<ll> a;
		for(int i=1;i<=n;i++){
			f[i]=0;
			cin>>num[i];
		}
		for(int i=1;i<=n;i++){
			if(f[i]) continue;
			ll temp=i;
			while(!f[temp]){
				a.push_back(temp);
				f[temp]=1;
				temp=num[temp];
			}
		}
		for(auto it:a){
			cout<<it<<" ";
		}
		cout<<'\n';
	} 
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

1 2 3 4 
1 6 2 5 3 4 

result:

ok Correct (2 test cases)

Test #2:

score: 0
Accepted
time: 1ms
memory: 5584kb

input:

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

output:

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

result:

ok Correct (873 test cases)

Test #3:

score: 0
Accepted
time: 28ms
memory: 3536kb

input:

46233
7
2 1 7 5 3 4 6
7
5 6 2 4 3 7 1
4
3 4 1 2
7
4 5 1 6 3 2 7
8
4 2 6 5 1 3 8 7
8
3 4 8 6 7 5 2 1
7
6 2 4 3 7 1 5
8
8 1 3 2 7 4 6 5
8
6 5 4 2 1 3 7 8
8
8 3 5 6 2 7 1 4
8
7 3 6 1 8 5 2 4
8
2 3 4 5 8 6 1 7
8
5 8 2 4 7 3 1 6
8
3 4 8 2 7 5 6 1
8
2 8 3 5 7 4 6 1
8
8 4 5 7 6 1 2 3
8
5 2 6 3 4 7 8 1
8
2 ...

output:

1 2 3 7 6 4 5 
1 5 3 2 6 7 4 
1 3 2 4 
1 4 6 2 5 3 7 
1 4 5 2 3 6 7 8 
1 3 8 2 4 6 5 7 
1 6 2 3 4 5 7 
1 8 5 7 6 4 2 3 
1 6 3 4 2 5 7 8 
1 8 4 6 7 2 3 5 
1 7 2 3 6 5 8 4 
1 2 3 4 5 8 7 6 
1 5 7 2 8 6 3 4 
1 3 8 2 4 5 7 6 
1 2 8 3 4 5 7 6 
1 8 3 5 6 2 4 7 
1 5 4 3 6 7 8 2 
1 2 4 7 3 5 6 8 
1 5 6 3 2 ...

result:

ok Correct (46233 test cases)

Test #4:

score: -100
Runtime Error

input:

1
999995
992870 548521 579550 387108 249895 990007 476463 686591 907510 311379 340877 491996 478527 996443 681309 483046 760005 905577 711115 275827 697004 737465 904964 381424 774578 217570 554656 914370 935328 624905 590395 761191 265062 978389 670994 184745 662928 389422 952905 447853 325275 9796...

output:


result: