Task: | Vaihdot |
Sender: | Olli |
Submission time: | 2020-10-17 09:25:50 +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 |
Compiler report
input/code.cpp: In function 'void solve()': input/code.cpp:100:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] for(int i = 0; i < ans.size(); ++i) { ~~^~~~~~~~~~~~
Code
#include <iostream> #include <vector> #include <algorithm> using namespace std; typedef pair<int, int> pii; vector<pii> ans; vector<int> v; int n; bool sol; void solveBrute(int k, int d) { if(sol) return; if(d >= 6) return; bool thisSol = true; for(int i = 1; i <= k; ++i) { if(v[i-1] != i) { thisSol = false; break; } } if(thisSol) { sol = true; return; } for(int i = 0; i < k; ++i) { for(int j = i+2; j < k; ++j) { ans.push_back({i+1, j+1}); swap(v[i], v[j]); solveBrute(k, d+1); if(sol) { break; } swap(v[i], v[j]); ans.pop_back(); } if(sol) break; } } void solve() { if(n == 1) { cout << "0\n"; return; } if(n == 2) { if(v[0] == 1) { cout << "0\n"; } else { cout << "-1\n"; } return; } if(n == 3) { if(v[1] != 2) { cout << "-1\n"; } else { if(v[0] == 1) { cout << "0\n"; } else { cout << "1\n"; cout << "1 3\n"; } } return; } for(int i = n; i >= 1; --i) { int j = -1; for(int k = 0; k < n; ++k) { if(v[k] == i) { j = k; break; } } if(j == i-1) continue; if(j < i-2) { ans.push_back({j+1, i}); swap(v[j], v[i-1]); continue; } if(j >= 2) { ans.push_back({j+1, 1}); swap(v[j], v[0]); ans.push_back({i, 1}); swap(v[i-1], v[0]); continue; } solveBrute(4, 0); break; } cout << ans.size() << "\n"; for(int i = 0; i < ans.size(); ++i) { cout << ans[i].first << " " << ans[i].second << "\n"; } } int main() { iostream::sync_with_stdio(false); cin.tie(0); int t; cin >> t; for(int q = 1; q <= t; ++q) { cin >> n; for(int i = 1; i <= n; ++i) { int a; cin >> a; v.push_back(a); } solve(); v.clear(); ans.clear(); } }
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 |
---|
83 67 79 70 78 3 77 60 76 ... Truncated |