CSES - Putka Open 2020 – 3/5 - Results
Submission details
Task:Vaihdot
Sender:ollpu
Submission time:2020-10-16 18:12:51 +0300
Language:C++ (C++17)
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
Test results
testverdicttimegroup
#10.02 s1, 2details
#20.10 s2details

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:47:11: warning: 'x' may be used uninitialized in this function [-Wmaybe-uninitialized]
       int x;
           ^

Code

#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int T;
cin >> T;
for (int Ti = 0; Ti < T; ++Ti) {
int n;
cin >> n;
int t[n];
for (int i = 0; i < n; ++i) cin >> t[i];
if (n == 2) {
cout << (t[0] == 1 ? 0 : -1) << endl;
continue;
}
if (n == 3) {
if (t[1] != 2) {
cout << -1 << endl;
} else if (t[0] != 1) {
cout << "1\n1 3\n";
} else {
cout << "0\n";
}
continue;
}
vector<pair<int, int>> res;
auto swp = [&](int a, int b) {
swap(t[a], t[b]);
if (b > a) swap(a, b);
if (b == a+1) {
if (a > 1) {
res.emplace_back(0, b);
res.emplace_back(0, a);
res.emplace_back(0, b);
} else {
res.emplace_back(b, n-1);
res.emplace_back(a, n-1);
res.emplace_back(b, n-1);
}
} else {
res.emplace_back(a, b);
}
};
for (int i = 0; i < n; ++i) {
if (t[i] == i+1) continue;
int x;
for (int j = i+1; j < n; ++j) {
if (t[j] == i+1) {
x = j;
break;
}
}
swp(i, x);
}
cout << res.size() << endl;
for (auto [a, b] : res) cout << a+1 << " " << b+1 << endl;
}
}

Test details

Test 1

Group: 1, 2

Verdict:

input
1000
1
1
2
1 2
...

correct output
0
0
-1
0
-1
...

user output
0
0
-1
0
-1
...
Truncated

Test 2

Group: 2

Verdict:

input
1000
79
49 42 77 41 37 61 46 55 7 72 4...

correct output
81
67 79
70 78
3 77
60 76
...

user output
75
58 1
45 2
16 3
29 4
...
Truncated