QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#493179#8838. Jesse's Jobflorrio#WA 2ms3692kbC++141010b2024-07-26 20:45:592024-07-26 20:45:59

Judging History

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

  • [2024-07-26 20:45:59]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3692kb
  • [2024-07-26 20:45:59]
  • 提交

answer

#include<iostream>
#include<vector>
#define int long long
#define No NO
#define Yes YES
using namespace std;
const int N=2e5+5,mod=998244353;
int T,n,t[N],vis[N];
vector<int> v;
int ab(int a){
	if(a>0) return a;
	return -a;
}
signed main(){
	ios::sync_with_stdio(0);
    cin>>T;
    while(T--){
    	cin>>n;
    	for(int i=1;i<=n;i++) cin>>t[i];
    	int cnt=0;
    	v.clear();
    	for(int i=1;i<=n;i++){
    		if(vis[i]) continue;
    		cnt++;
    		int c=i;
    		while((!vis[c])||c!=i){
    			vis[c]=1;
    			if(i==1) v.push_back(c);
    			c=t[c];
			}
		}
		for(int i=1;i<=n;i++) vis[i]=0;
		if(cnt>1){
			cout<<n<<"\n";
			cout<<v.size()<<"\n";
			for(auto ver:v) cout<<ver<<" ";
			cout<<"\n";
			v.clear();
			continue;
		}
		v.clear();
		int ans=1e9; 
		for(int i=1;i<=n;i++) ans=min(ans,ab(i-t[i]));
		cout<<n-ans-1<<"\n";
		cout<<"1\n";
		for(int i=1;i<=n;i++){
			if(ab(i-t[i])==ans){
				cout<<i<<"\n";
				break;
			}
		}
	}
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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
1
3

result:

ok Correct (3 test cases)

Test #2:

score: -100
Wrong Answer
time: 2ms
memory: 3624kb

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 5 4 3 
4
2
1 2 
6
3
1 2 3 
6
4
1 4 6 3 
6
4
1 6 5 4 
5
2
1 2 
6
1
1 
4
2
1 2 
6
1
1 
6
3
1 6 2 
6
2
1 2 
6
2
1 3 
6
5
1 4 3 5 2 
6
3
1 5 3 
6
3
1 4 2 
6
3
1 5 2 
6
2
1 6 
6
5
1 6 4 3 5 
6
4
1 5 3 4 
6
5
1 6 5 4 2 
6
5
1 2 3 4 6 
6
5
1 5 3 2 6 
6
2
1 4 
4
1
2
6
2
1 3 
6
1
1 
6
1
1 
6
1
1...

result:

wrong answer Jury found better answer than participant (test case 143)