QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#460352#8835. Goodmanchenxinyang2006WA 0ms8060kbC++201.5kb2024-07-01 14:22:082024-07-01 14:22:08

Judging History

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

  • [2024-07-01 14:22:08]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:8060kb
  • [2024-07-01 14:22:08]
  • 提交

answer

#include <bits/stdc++.h>
#define rep(i,j,k) for(int i=(j);i<=(k);i++)
#define per(i,j,k) for(int i=(j);i>=(k);i--)
#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define db double
#define ldb long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mkp make_pair
#define eb emplace_back
#define SZ(S) (int)S.size()
//#define mod 998244353
//#define mod 1000000007
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3f
using namespace std;

template <class T>
void chkmax(T &x,T y){
	if(x < y) x = y;
}

template <class T>
void chkmin(T &x,T y){
	if(x > y) x = y;
}

inline int popcnt(int x){
	return __builtin_popcount(x);
}

inline int ctz(int x){
	return __builtin_ctz(x);
}


/*ll power(ll p,int k = mod - 2){
	ll ans = 1;
	while(k){
		if(k % 2 == 1) ans = ans * p % mod;
		p = p * p % mod;
		k /= 2;	
	}
	return ans;
}*/
int T,n;
int a[1000005],vis[1000005];

int k;
int idx[1000005];
void solve(){
	scanf("%d",&n);
	rep(i,1,n) scanf("%d",&a[i]);
	fill(vis,vis + n + 1,0);
	rep(i,1,n){
		if(vis[i]) continue;
		k = 0;
		int p = i;
		while(!vis[p]){
			idx[++k] = p;
			vis[p] = 1;
			p = a[p];
		}
		if(k == 1){
			printf("%d ",idx[1]);
			continue;
		}
		for(int s = 2;s <= k;s += 2) printf("%d ",idx[s]);
		for(int s = 1;s <= k;s += 2) printf("%d ",idx[s]);
	}
	printf("\n");
}

int main(){
//	freopen("test.in","r",stdin);
	scanf("%d",&T);
	while(T--) solve();
	return 0;
}

详细

Test #1:

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

input:

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

output:

1 2 3 4 
6 1 5 2 4 3 

result:

ok Correct (2 test cases)

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 8060kb

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

result:

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