QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#478196 | #8838. Jesse's Job | Golden | WA | 0ms | 3484kb | C++17 | 1.2kb | 2024-07-14 18:41:24 | 2024-07-14 18:41:24 |
Judging History
answer
#include <iostream>
#include <vector>
using namespace std;
const int N = 1e6 + 5;
int p[N];
bool was[N];
void solve() {
int n; cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> p[i];
was[i] = false;
}
vector<int> cycle;
int ind = 1;
while (!was[p[ind]]) {
was[p[ind]] = true;
cycle.push_back(ind);
ind = p[ind];
}
if ((int)cycle.size() == n) {
if (n == 2) {
if (p[1] != 1)
cout << "0\n1\n1\n";
else
cout << "2\n1\n1\n";
return;
}
else {
cout << n - 2 << "\n";
cycle.pop_back(), cycle.pop_back();
cout << cycle.size() << "\n";
for (int val : cycle) {
cout << val << " ";
}
cout << "\n";
}
}
else {
cout << n << "\n";
cout << cycle.size() << "\n";
for (int val : cycle) {
cout << val << " ";
}
cout << "\n";
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int t; cin >> t;
while (t--) solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3484kb
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 4 1 3 4 2
result:
wrong answer Participant didn't find permutation (test case 3)