Task: | Vaihdot |
Sender: | rasastusni |
Submission time: | 2020-10-17 18:56:14 +0300 |
Language: | C++ (C++17) |
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.12 s | 2 | details |
Compiler report
input/code.cpp: In function 'void solve(std::vector<int>&)': input/code.cpp:9:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] for (int i = 0; i < v.size(); ++i) { ~~^~~~~~~~~~ input/code.cpp:11:9: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] if (i == v.size() - 1) { ~~^~~~~~~~~~~~~~~ input/code.cpp:18:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] for (k = 0; k < v.size(); ++k) { ~~^~~~~~~~~~ input/code.cpp:37:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] for (int j = i + 1; j < v.size(); ++j) { ~~^~~~~~~~~~
Code
#include <iostream> #include <utility> #include <vector> using namespace std; void solve(vector<int> &v) { vector<pair<int, int>> m; for (int i = 0; i < v.size(); ++i) { if (v[i] == i + 1) continue; if (i == v.size() - 1) { cout << -1 << endl; return; } if (v[i+1] == i + 1 && v[i] == i + 2) { int k; bool ok = false; for (k = 0; k < v.size(); ++k) { if (k == i || k == i + 1) continue; if (abs(v[k] - v[i+1]) == 1) continue; ok = true; break; } if (!ok) { cout << -1 << endl; return; } swap(v[i+1], v[k]); m.push_back(make_pair(i+2, k+1)); swap(v[k], v[i]); m.push_back(make_pair(k+1, i+1)); if (k < i) { swap(v[i+1], v[k]); m.push_back(make_pair(i+2, k+1)); } } else { for (int j = i + 1; j < v.size(); ++j) { if (v[j] == i + 1) { swap(v[i], v[j]); m.push_back(make_pair(i+1, j+1)); } } } if (m.size() > 5 * v.size()) { cout << -1 << endl; return; } } cout << m.size() << endl; for (auto &p : m) { cout << p.first << " " << p.second << endl; } } int main() { int t; cin >> t; for (int i = 0; i < t; ++i) { int n; cin >> n; vector<int> v(n); for (int a = 0; a < n; ++a) { cin >> v[a]; } 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 |
---|
79 1 58 2 45 3 16 4 29 ... Truncated |