CSES - Aalto Competitive Programming 2024 - wk4 - Wed - Results
Submission details
Task:Pair sort
Sender:aalto2024d_005
Submission time:2024-09-25 17:48:18 +0300
Language:C++ (C++11)
Status:READY
Result:
Test results
testverdicttime
#10.00 sdetails
#20.00 sdetails
#30.00 sdetails
#40.00 sdetails
#50.00 sdetails
#60.00 sdetails
#70.00 sdetails
#80.00 sdetails
#90.00 sdetails
#100.00 sdetails
#110.01 sdetails
#120.00 sdetails
#130.01 sdetails
#140.01 sdetails

Code

#include <bits/stdc++.h>
using namespace std;
#define debug(x) cerr << #x << ": " << x << endl;
void swap(int arr[], int i, int k) {
int temp = arr[i];
arr[i] = arr[k];
arr[k] = temp;
}
int main() {
int n;
cin >> n;
int arr[n];
for (int i = 0; i < 2*n; i++)
{
cin >> arr[i];
}
int swaps = 0;
for (int i = 0; i < 2*n-1; i++)
{
if (arr[i] == arr[i+1]) {
continue;
}
for (int j = i+2; j < 2*n; j++)
{
if (arr[j] == arr[i+1]) {
swap(arr, i, j);
swaps++;
}
}
}
cout << swaps << endl;
for (int i = 0; i < 2*n; i++)
{
cout << arr[i] << ' ';
}
cout << endl;
return 0;
}

Test details

Test 1

Verdict:

input
5
3 2 4 5 1 3 2 1 4 5 

correct output
3
2 6
4 9
6 8

user output
5
2 4 5 1 3 3 1 5 

Test 2

Verdict:

input
5
3 2 4 5 1 3 2 1 4 5 

correct output
3
2 6
4 9
6 8

user output
5
2 4 5 1 3 3 1 5 

Test 3

Verdict:

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
1
6 6 3 8 

Test 4

Verdict:

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
1
6 6 3 8 

Test 5

Verdict:

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
9
47 26 35 35 13 18 9 14 14 34 3...
Truncated

Test 6

Verdict:

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
9
47 26 35 35 13 18 9 14 14 34 3...
Truncated

Test 7

Verdict:

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
48
26 6 35 35 72 9 55 83 51 58 

Error:
*** stack smashing detected ***: terminated

Test 8

Verdict:

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
48
26 6 35 35 72 9 55 83 51 58 

Error:
*** stack smashing detected ***: terminated

Test 9

Verdict:

input
500
56 146 351 35 281 235 354 449 ...

correct output
497
2 758
4 820
6 125
8 243
...

user output
13
56 146 351 281 281 235 354 83 ...
Truncated

Test 10

Verdict:

input
500
56 146 351 35 281 235 354 449 ...

correct output
497
2 758
4 820
6 125
8 243
...

user output
13
56 146 351 281 281 235 354 83 ...
Truncated

Test 11

Verdict:

input
1000
603 596 351 885 530 235 354 56...

correct output
993
2 256
4 1534
6 816
8 1057
...

user output
117
603 596 351 885 235 235 354 56...
Truncated

Test 12

Verdict:

input
1000
603 596 351 885 530 235 354 56...

correct output
993
2 256
4 1534
6 816
8 1057
...

user output
117
603 596 351 885 235 235 354 56...
Truncated

Test 13

Verdict:

input
5000
1594 596 1797 3776 1201 235 35...

correct output
4993
2 1548
4 9062
6 6397
8 8296
...

user output
285
1594 596 1797 3776 1201 235 35...
Truncated

Test 14

Verdict:

input
5000
1594 596 1797 3776 1201 235 35...

correct output
4993
2 1548
4 9062
6 6397
8 8296
...

user output
285
1594 596 1797 3776 1201 235 35...
Truncated