QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#707994 | #8838. Jesse's Job | jiujiu | WA | 0ms | 3548kb | C++14 | 1.1kb | 2024-11-03 18:46:08 | 2024-11-03 18:46:14 |
Judging History
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)