QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#707994#8838. Jesse's JobjiujiuWA 0ms3548kbC++141.1kb2024-11-03 18:46:082024-11-03 18:46:14

Judging History

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

  • [2024-11-03 18:46:14]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3548kb
  • [2024-11-03 18:46:08]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) x.begin(), x.end()

void sovle(){
	int n;
	std::cin >> n;
	std::vector<int> v(n + 1);
	for(int i = 1; i <= n; i++){
		std::cin >> v[i];
	}
	std::vector<int> vis(n + 1);
	std::vector<std::vector<int>> p;
	int flag = 0;
	for(int i = 1; i <= n; i++){
		if(!vis[v[i]]){
			int x = v[i], cnt = 0;
			std::vector<int> temp;
			while(!vis[x]){
				vis[x] = 1;
				x = v[x];		
				temp.push_back(x);
				cnt++;
			}
			p.push_back(temp);
			if(cnt == n){flag = 1;break;}
		}
	}
	if(flag){
		std::cout << n - 2 << "\n" << n / 2 << '\n';
        for(int i = 0; i < n / 2; i++){
            std::cout << p[0][i] << " \n"[i == n / 2 - 1];
        }
	} else {
		std::cout << n << "\n";
		std::cout << p[0].size() << "\n";
		std::sort(all(p[0]));
		for(auto i : p[0]){
			std::cout << i << " ";
		}
		std::cout << "\n";
	}

}

signed main(){
    std::ios::sync_with_stdio(false),std::cin.tie(0),std::cout.tie(0);
    int _ = 1;
    std::cin >> _;
    while(_--){
        sovle();
    }
	return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3548kb

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
4 2 5

result:

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