Task: | Vaihdot |
Sender: | kluopaja |
Submission time: | 2020-10-18 19:20:53 +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.02 s | 1, 2 | details |
#2 | WRONG ANSWER | 0.08 s | 2 | details |
Compiler report
input/code.cpp: In function 'void solve(std::vector<int>)': input/code.cpp:101:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] for(int i = 0; i < v.size(); ++i) { ~~^~~~~~~~~~
Code
#include <iostream>#include <vector>#include <utility>using namespace std;// assume n >= 4// if i == 1// a b c// a c b// b c a// b a c// if i == 2// d a b c, a c// d c b a, a d// a c b d, a b// b c a d, b d// d c a b, b c// d b a c// if i == 3// c a b, c b// b a c, a b// a b c, a c// c b a// 1 2 3 4 5 6 7 8void printAns(vector<pair<int, int> > v) {cout<<v.size()<<endl;for(auto x: v) {cout<<x.first+1<<' '<<x.second+1<<endl;}}void swap_two(vector<int>& v, int a, int b, vector<pair<int, int> >& ans) {if(a > b) swap(a, b);int c;swap(v[a], v[b]);if(a+1 == b) {if(b == 1) {c = 3;ans.push_back({b, c});swap(b, c);ans.push_back({a, b});swap(a, b);ans.push_back({a, c});}int d;if(b == 2) {d = 0;c = 3;ans.push_back({a, c});swap(a, c);ans.push_back({a, d});swap(a, d);ans.push_back({a, b});swap(a, b);ans.push_back({b, d});swap(b, d);ans.push_back({b, c});}if(b == 3) {c = 0;ans.push_back({c, b});swap(c, b);ans.push_back({a, b});swap(a, b);ans.push_back({a, c});}}else {ans.push_back({a, b});}}void solve(vector<int> v) {if(v.size() == 1) {cout<<0<<endl;return;}if(v.size() == 2) {if(v[0] == 0) {cout<<0<<endl;return;}cout<<-1<<endl;return;}vector<pair<int, int> > ans;if(v.size() == 3) {if(v[0] > v[2]) {swap(v[0], v[2]);ans.push_back({0, 2});}if(v[0] == 0 && v[1] == 1 && v[2] == 2) {printAns(ans);return;}else {cout<<-1<<endl;return;}}for(int i = 0; i < v.size(); ++i) {if(v[i] != i) {swap_two(v, i, v[i], ans);}}printAns(ans);}int main() {int tt;cin>>tt;for(int xx = 0; xx < tt; ++xx) {int n;cin>>n;vector<int> v(n);for(int i = 0; i < n; ++i) {cin>>v[i];--v[i];}solve(v);}}
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 |
---|
50 1 49 2 42 3 77 4 41 ... Truncated |