Task: | Pair sort |
Sender: | aalto2024d_001 |
Submission time: | 2024-09-25 17:15:15 +0300 |
Language: | C++ (C++11) |
Status: | READY |
Result: | ACCEPTED |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.00 s | details |
#2 | ACCEPTED | 0.00 s | details |
#3 | ACCEPTED | 0.00 s | details |
#4 | ACCEPTED | 0.00 s | details |
#5 | ACCEPTED | 0.00 s | details |
#6 | ACCEPTED | 0.00 s | details |
#7 | ACCEPTED | 0.00 s | details |
#8 | ACCEPTED | 0.00 s | details |
#9 | ACCEPTED | 0.00 s | details |
#10 | ACCEPTED | 0.00 s | details |
#11 | ACCEPTED | 0.00 s | details |
#12 | ACCEPTED | 0.00 s | details |
#13 | ACCEPTED | 0.01 s | details |
#14 | ACCEPTED | 0.01 s | details |
Code
#include <cstdio> #include <iostream> #include <utility> #include <vector> using namespace std; int main(int argc, char *argv[]) { // Read the input parameters int n; cin >> n; // Read values from one line vector<int> occurence(n + 1, -1); vector<int> input_line(2*n); for (int i = 0; i < 2 * n; i++) { int tmp; cin >> tmp; if (occurence[tmp] == -1) { occurence[tmp] = i; } input_line[i] = tmp; } // for (int i = 0; i < n + 1; i++) { // cout << occurence[i] << " "; // } // cout << "\n"; vector<pair<int, int>> swaps; int swaps_amount = 0; for (int i = 2*n - 1; i > 1; i -= 2) { if (input_line[i] == input_line[i-1]) continue; else { int og_value = input_line[i]; // cout << input_line[i-1] << " "; int first_index = occurence[input_line[i-1]]; // cout << input_line[i] << "\n"; // swap to match the pair swaps.push_back({i + 1, first_index + 1}); swaps_amount++; // int tmp = input_line[i]; input_line[first_index] = input_line[i]; input_line[i] = input_line[i-1]; // update the first location of i // cout << input_line[i] << " " << occurence[input_line[i]] << "\n"; if (occurence[og_value] > first_index) { occurence[og_value] = first_index; } } } cout << swaps_amount << "\n"; for (int i = 0; i < swaps_amount; i++) { cout << swaps[i].first << " " << swaps[i].second << "\n"; } // for (int i = 0; i < n + 1; i++) { // cout << occurence[i] << " "; // } // cout << "\n"; return 0; }
Test details
Test 1
Verdict: ACCEPTED
input |
---|
5 3 2 4 5 1 3 2 1 4 5 |
correct output |
---|
3 2 6 4 9 6 8 |
user output |
---|
3 10 3 8 2 6 2 |
Test 2
Verdict: ACCEPTED
input |
---|
5 3 2 4 5 1 3 2 1 4 5 |
correct output |
---|
3 2 6 4 9 6 8 |
user output |
---|
3 10 3 8 2 6 2 |
Test 3
Verdict: ACCEPTED
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 |
---|
9 20 16 18 1 16 8 14 1 ... |
Test 4
Verdict: ACCEPTED
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 |
---|
9 20 16 18 1 16 8 14 1 ... |
Test 5
Verdict: ACCEPTED
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 |
---|
48 100 2 98 44 96 10 94 10 ... Truncated |
Test 6
Verdict: ACCEPTED
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 |
---|
48 100 2 98 44 96 10 94 10 ... Truncated |
Test 7
Verdict: ACCEPTED
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 |
---|
97 200 135 198 37 196 32 194 125 ... Truncated |
Test 8
Verdict: ACCEPTED
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 |
---|
97 200 135 198 37 196 32 194 125 ... Truncated |
Test 9
Verdict: ACCEPTED
input |
---|
500 56 146 351 35 281 235 354 449 ... |
correct output |
---|
497 2 758 4 820 6 125 8 243 ... |
user output |
---|
497 1000 530 998 366 996 507 994 355 ... Truncated |
Test 10
Verdict: ACCEPTED
input |
---|
500 56 146 351 35 281 235 354 449 ... |
correct output |
---|
497 2 758 4 820 6 125 8 243 ... |
user output |
---|
497 1000 530 998 366 996 507 994 355 ... Truncated |
Test 11
Verdict: ACCEPTED
input |
---|
1000 603 596 351 885 530 235 354 56... |
correct output |
---|
993 2 256 4 1534 6 816 8 1057 ... |
user output |
---|
993 2000 1410 1998 1555 1996 562 1994 648 ... Truncated |
Test 12
Verdict: ACCEPTED
input |
---|
1000 603 596 351 885 530 235 354 56... |
correct output |
---|
993 2 256 4 1534 6 816 8 1057 ... |
user output |
---|
993 2000 1410 1998 1555 1996 562 1994 648 ... Truncated |
Test 13
Verdict: ACCEPTED
input |
---|
5000 1594 596 1797 3776 1201 235 35... |
correct output |
---|
4993 2 1548 4 9062 6 6397 8 8296 ... |
user output |
---|
4993 10000 964 9998 1015 9996 8800 9994 3220 ... Truncated |
Test 14
Verdict: ACCEPTED
input |
---|
5000 1594 596 1797 3776 1201 235 35... |
correct output |
---|
4993 2 1548 4 9062 6 6397 8 8296 ... |
user output |
---|
4993 10000 964 9998 1015 9996 8800 9994 3220 ... Truncated |