Task: | Järjestys |
Sender: | ankka22 |
Submission time: | 2016-10-16 13:07:13 +0300 |
Language: | C++ |
Status: | READY |
Result: | 100 |
group | verdict | score |
---|---|---|
#1 | ACCEPTED | 19 |
#2 | ACCEPTED | 37 |
#3 | ACCEPTED | 44 |
test | verdict | time | group | |
---|---|---|---|---|
#1 | ACCEPTED | 0.06 s | 1 | details |
#2 | ACCEPTED | 0.06 s | 2 | details |
#3 | ACCEPTED | 0.11 s | 3 | details |
Compiler report
input/code.cpp: In function 'int main()': input/code.cpp:63:29: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] for (int i = 0; i < s.size(); i++) { ^
Code
#include <iostream> #include <math.h> #include <algorithm> static void sswap(std::vector<int> &s, int n) { if (n == 3) { s.push_back(3); s.push_back(2); s.push_back(2); return; } else if (n == 2) { s.push_back(2); return; } else if (n == 1) { return; } s.push_back(n); s.push_back(n - 1); s.push_back(n - 2); s.push_back(n - 1); } int main() { int n; std::vector<int> v; std::vector<int> s; std::vector<int> nr; std::cin >> n; int arr[1000001]; for (int i = 1; i < n+1; i++) { int t; std::cin >> t; arr[i] = t; v.push_back(t); } int c = 0; int ready = 0; while (c < 5*n) { int firstRN = arr[1]; if (firstRN == 1) { bool fail = false; for (int i = 2; i < n + 1; i++) { if (arr[i] != i) { arr[1] = arr[i]; arr[i] = 1; sswap(s, i); fail = true; break; } } if (!fail) { break; } else { continue; } } arr[1] = arr[firstRN]; arr[firstRN] = firstRN; sswap(s, firstRN); ready++; c++; } std::cout << s.size() << std::endl; for (int i = 0; i < s.size(); i++) { std::cout << s.at(i) << " "; } std::cout << std::endl; return 0; }
Test details
Test 1
Group: 1
Verdict: ACCEPTED
input |
---|
10 9 3 4 7 6 5 10 2 8 1 |
correct output |
---|
32 10 10 9 10 9 8 7 9 4 2 1 4 5 2... |
user output |
---|
36 9 8 7 8 8 7 6 7 2 3 2 2 4 3 2 ... |
Test 2
Group: 2
Verdict: ACCEPTED
input |
---|
1000 650 716 982 41 133 1000 876 92... |
correct output |
---|
3984 207 207 206 207 128 127 126 12... |
user output |
---|
3996 650 649 648 649 328 327 326 32... |
Test 3
Group: 3
Verdict: ACCEPTED
input |
---|
100000 94703 47808 62366 31885 7091 8... |
correct output |
---|
399956 98676 98676 98675 98676 62994 ... |
user output |
---|
400027 94703 94702 94701 94702 71577 ... |