Task: | Pair sort |
Sender: | aalto2024d_006 |
Submission time: | 2024-09-25 16:54:13 +0300 |
Language: | C++ (C++11) |
Status: | READY |
Result: | WRONG ANSWER |
test | verdict | time | |
---|---|---|---|
#1 | WRONG ANSWER | 0.00 s | details |
#2 | WRONG ANSWER | 0.00 s | details |
#3 | WRONG ANSWER | 0.00 s | details |
#4 | WRONG ANSWER | 0.00 s | details |
#5 | WRONG ANSWER | 0.00 s | details |
#6 | WRONG ANSWER | 0.00 s | details |
#7 | WRONG ANSWER | 0.00 s | details |
#8 | WRONG ANSWER | 0.00 s | details |
#9 | WRONG ANSWER | 0.00 s | details |
#10 | WRONG ANSWER | 0.00 s | details |
#11 | WRONG ANSWER | 0.00 s | details |
#12 | WRONG ANSWER | 0.00 s | details |
#13 | WRONG ANSWER | 0.01 s | details |
#14 | WRONG ANSWER | 0.01 s | details |
Compiler report
input/code.cpp: In function 'void Test()': input/code.cpp:15:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result] 15 | freopen("temp\\in.txt", "r", stdin); | ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~ input/code.cpp: In function 'int main()': input/code.cpp:21:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result] 21 | scanf("%d", &n); | ~~~~~^~~~~~~~~~ input/code.cpp:24:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result] 24 | scanf("%d", &a[i]); | ~~~~~^~~~~~~~~~~~~
Code
#include<iostream> #include<cstdio> #include<vector> #include<algorithm> typedef long long LL; typedef std::pair<int, int> poi; using std::make_pair; using std::vector; const int N=100005; int a[2*N], b[2*N]; poi p[N], pr[N]; void Test() { freopen("temp\\in.txt", "r", stdin); } int main() { // Test(); int n, k=0, kr=0; scanf("%d", &n); for(int i=1; i<=2*n; i++) { scanf("%d", &a[i]); b[i] = a[i]; if(p[a[i]].first == 0) { p[a[i]].first = i; } else { p[a[i]].second = i; } } for(int i=1; i<=n; i++) pr[i] = make_pair(p[i].first, p[i].second); vector<poi> ans, ansr; for(int i=1; i<=2*n; i+=2) { if(a[i] == a[i+1]) continue; k++; // swap i+1, j poi px = p[a[i]], py = p[a[i+1]]; int j = px.second; py.first = j; std::swap(a[i+1], j); if(py.first > py.second) std::swap(py.first, py.second); ans.push_back(make_pair(i+1, j)); } for(int i=1; i<=2*n; i+=2) { if(b[i] == b[i+1]) continue; kr++; // swap i, j poi px = pr[b[i+1]], py = pr[b[i]]; int j = px.second; py.first = j; std::swap(b[i], b[j]); if(py.first > py.second) std::swap(py.first, py.second); ansr.push_back(make_pair(i, j)); } // printf("%d %d\n", k, kr); if(k <= kr) { printf("%d\n", k); for(auto it = ans.begin(); it != ans.end(); it++) printf("%d %d\n", (*it).first, (*it).second); } else { printf("%d\n", kr); for(auto it = ansr.begin(); it != ansr.end(); it++) printf("%d %d\n", (*it).first, (*it).second); } return 0; }
Test details
Test 1
Verdict: WRONG ANSWER
input |
---|
5 3 2 4 5 1 3 2 1 4 5 |
correct output |
---|
3 2 6 4 9 6 8 |
user output |
---|
4 1 7 3 10 5 6 7 8 |
Test 2
Verdict: WRONG ANSWER
input |
---|
5 3 2 4 5 1 3 2 1 4 5 |
correct output |
---|
3 2 6 4 9 6 8 |
user output |
---|
4 1 7 3 10 5 6 7 8 |
Test 3
Verdict: WRONG ANSWER
input |
---|
10 3 6 6 8 8 9 9 1 4 5 2 4 10 2 1... |
correct output |
---|
9 2 17 4 17 6 17 8 17 ... |
user output |
---|
10 2 6 4 8 6 9 8 1 ... |
Test 4
Verdict: WRONG ANSWER
input |
---|
10 3 6 6 8 8 9 9 1 4 5 2 4 10 2 1... |
correct output |
---|
9 2 17 4 17 6 17 8 17 ... |
user output |
---|
10 2 6 4 8 6 9 8 1 ... |
Test 5
Verdict: WRONG ANSWER
input |
---|
50 47 26 6 35 13 18 9 19 14 50 34... |
correct output |
---|
48 2 87 4 78 6 71 8 55 ... |
user output |
---|
50 2 26 4 35 6 18 8 19 ... Truncated |
Test 6
Verdict: WRONG ANSWER
input |
---|
50 47 26 6 35 13 18 9 19 14 50 34... |
correct output |
---|
48 2 87 4 78 6 71 8 55 ... |
user output |
---|
50 2 26 4 35 6 18 8 19 ... Truncated |
Test 7
Verdict: WRONG ANSWER
input |
---|
100 56 26 6 35 60 72 9 55 83 51 58... |
correct output |
---|
97 2 77 4 108 6 141 8 55 ... |
user output |
---|
99 2 26 4 35 6 72 8 55 ... Truncated |
Test 8
Verdict: WRONG ANSWER
input |
---|
100 56 26 6 35 60 72 9 55 83 51 58... |
correct output |
---|
97 2 77 4 108 6 141 8 55 ... |
user output |
---|
99 2 26 4 35 6 72 8 55 ... Truncated |
Test 9
Verdict: WRONG ANSWER
input |
---|
500 56 146 351 35 281 235 354 449 ... |
correct output |
---|
497 2 758 4 820 6 125 8 243 ... |
user output |
---|
500 2 146 4 35 6 235 8 449 ... Truncated |
Test 10
Verdict: WRONG ANSWER
input |
---|
500 56 146 351 35 281 235 354 449 ... |
correct output |
---|
497 2 758 4 820 6 125 8 243 ... |
user output |
---|
500 2 146 4 35 6 235 8 449 ... Truncated |
Test 11
Verdict: WRONG ANSWER
input |
---|
1000 603 596 351 885 530 235 354 56... |
correct output |
---|
993 2 256 4 1534 6 816 8 1057 ... |
user output |
---|
999 1 701 3 1198 5 529 7 1861 ... Truncated |
Test 12
Verdict: WRONG ANSWER
input |
---|
1000 603 596 351 885 530 235 354 56... |
correct output |
---|
993 2 256 4 1534 6 816 8 1057 ... |
user output |
---|
999 1 701 3 1198 5 529 7 1861 ... Truncated |
Test 13
Verdict: WRONG ANSWER
input |
---|
5000 1594 596 1797 3776 1201 235 35... |
correct output |
---|
4993 2 1548 4 9062 6 6397 8 8296 ... |
user output |
---|
4999 2 596 4 3776 6 235 8 1878 ... Truncated |
Test 14
Verdict: WRONG ANSWER
input |
---|
5000 1594 596 1797 3776 1201 235 35... |
correct output |
---|
4993 2 1548 4 9062 6 6397 8 8296 ... |
user output |
---|
4999 2 596 4 3776 6 235 8 1878 ... Truncated |