Task: | Vaihdot |
Sender: | Mahtimursu |
Submission time: | 2020-10-16 19:32:57 +0300 |
Language: | C++ (C++11) |
Status: | READY |
Result: | 0 |
group | verdict | score |
---|---|---|
#1 | WRONG ANSWER | 0 |
#2 | WRONG ANSWER | 0 |
test | verdict | time | group | |
---|---|---|---|---|
#1 | WRONG ANSWER | 0.01 s | 1, 2 | details |
#2 | WRONG ANSWER | 0.03 s | 2 | details |
Code
#include <bits/stdc++.h>typedef long long ll;#define M 1000000007using namespace std;void test_case() {int n;cin >> n;vector<int> v(n);for (int i = 0; i < n; ++i) {cin >> v[i];}vector<pair<int, int>> res;unsigned int sz = res.size();while (true) {for (int i = 0; i < n; ++i) {if (v[i] == i + 1) continue; // oikeaint id = v[i];if (abs(id - i - 1) == 1) continue;int tg = v[v[i]-1];v[v[i]-1] = v[i];v[i] = tg;res.push_back({i+1, id});}if (sz == res.size()) break;sz = res.size();}if (!is_sorted(v.begin(), v.end())) {if (n < 4) {cout << -1 << "\n";return;}for (int i = 0; i < n-1; ++i) {if (v[i] == i + 1) continue;// Use firstif (i >= n - 2) {res.push_back({1, i+1});res.push_back({1, i+2});res.push_back({1, i+1});v[i] = i + 1;v[i + 1] = i + 2;} else { // use lastres.push_back({i+1, n});res.push_back({i+2, n});res.push_back({i+1, n});v[i] = i + 1;v[i + 1] = i + 2;}}}// VASTAUScout << res.size() << "\n";for (auto val : res) {cout << val.first << " " << val.second << "\n";}}int main() {ios_base::sync_with_stdio(false);cin.tie(0);int t;cin >> t;for (int i = 0; i < t; ++i) {test_case();//cout << "\n";}return 0;}
Test details
Test 1
Group: 1, 2
Verdict: WRONG ANSWER
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: WRONG ANSWER
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 1 49 2 42 3 77 4 41 ... Truncated |