Task: | Vaihdot |
Sender: | tsiki2 |
Submission time: | 2020-10-18 20:32:28 +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.03 s | 1, 2 | details |
#2 | WRONG ANSWER | 0.56 s | 2 | details |
Compiler report
input/code.cpp: In function 'bool is_sorted(std::vector<int>&)': input/code.cpp:31:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] for (int i = 1; i < v.size(); i++) { ~~^~~~~~~~~~
Code
#include <stdio.h> // include before iostream for faster scanf#include <iostream>#include <vector>#include <string>#include <map>#include <unordered_map>#include <algorithm>#include <utility>#include <set>#include <unordered_set>#include <cmath>#include <math.h>#include <queue>#include <stdlib.h>#include <string.h>#include <sstream>#include <tuple>#include <utility>#include <iomanip>#include <iterator>using namespace std;typedef long long LL;#define printv(printVec) for (auto printVecIter : (printVec)) cout << printVecIter << " "; cout << endl;// g++ -Wall -Wshadow -std=c++11 a.cpp && ./a.outbool is_sorted(vector<int> & v) {for (int i = 1; i < v.size(); i++) {if (v[i] < v[i-1]) return false;}return true;}int main() {std::ios::sync_with_stdio(false);cin.tie(0);int t; cin>>t;while (t--) {int n; cin>>n;vector<int> ans(n);for (int i =0;i<n;i++) {cin>>ans[i];}if (ans.size() <= 2) {if (is_sorted(ans)) {cout << 0 << "\n";} else {cout << -1 << "\n";}continue;}if (ans.size() == 3) {if (!is_sorted(ans)) {swap(ans[0], ans[2]);if (is_sorted(ans)) {cout << 1 << "\n";cout << 1 << " " << 3 << "\n";} else {cout << -1 << "\n";}} else {cout << 0 << "\n";}continue;}vector<pair<int,int>> ops;for (int i = 0; i < n; i++) {int idx = i+1;printv(ans);if (ans[i] == i + 1) continue; // already in placewhile (ans[idx] != i+1) idx++;bool swapFirst = true;if (i == 0 || i == 1) {swapFirst = false;}if (swapFirst) {ops.push_back({i+1, 1});ops.push_back({1, idx+1});swap(ans[i], ans[idx]);} else {ops.push_back({i+1, n});if (idx != n-1) {ops.push_back({n, idx+1});}swap(ans[i], ans[idx]);}}cout << ops.size() << "\n";for (auto p : ops) {cout << p.first << " " << p.second << "\n";}}}
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 |
---|
49 42 77 41 37 61 46 55 7 72 4... Truncated |