Submission details
Task:Pair sort
Sender:aalto26dw_007
Submission time:2026-09-23 16:56:19 +0300
Language:Rust (2021)
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.00 sdetails
#120.00 sdetails
#130.01 sdetails
#140.01 sdetails

Code

#![allow(unused)]

use std::{io, thread::spawn};

fn take_int() -> usize {
    let mut input = String::new();
    io::stdin().read_line(&mut input).unwrap();
    return input.trim().parse::<usize>().unwrap();
}

fn take_vector() -> Vec<(usize, usize)> {
    let mut input = String::new();
    io::stdin().read_line(&mut input).unwrap();
    let arr: Vec<(usize, usize)> = input
        .trim()
        .split_whitespace()
        .map(|x| x.parse::<usize>().unwrap())
        .enumerate()
        .collect();
    return arr;
}

fn main() {
    let mut n: usize = take_int();
    let mut arr: Vec<(usize, usize)> = take_vector();
    let mut sorted = arr.clone();
    // println!("{:?}", arr);

    sorted.sort_unstable_by_key(|k| k.1);

    let mut i = 0;
    let mut count_swaps = 0;
    let mut swaps: Vec<(usize, usize)> = Vec::with_capacity(n);
    while i < n {
        let current = arr[i];
        if arr[i + 1] != current {
            count_swaps += 1;
            // needs swap with
            let index = sorted[current.1 * 2 + 1].0;
            // println!("index to change {}", index);
            swaps.push((i, index));

            let temp = arr[index];
            arr[index] = arr[i + 1];
            arr[i + 1] = temp;

            sorted[i * 2 + 1] = arr[i + 1];
        }
        // println!("{:?}", arr);
        i += 2;
    }
    println!("{}", count_swaps);
    for i in 0..swaps.len() {
        println!("{} {}", swaps[i].0+1, swaps[i].1+1);
    }
}

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
3
1 9
3 10
5 7

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
3
1 9
3 10
5 7

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
5
1 12
3 19
5 7
7 18
...

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
5
1 12
3 19
5 7
7 18
...

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
25
1 49
3 33
5 27
7 18
...

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
25
1 49
3 33
5 27
7 18
...

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
(empty)

Error:
thread 'main' panicked at input/code.rs:39:31:
index out of bounds: the len is 200 but the index is 201
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

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
(empty)

Error:
thread 'main' panicked at input/code.rs:39:31:
index out of bounds: the len is 200 but the index is 201
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

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
(empty)

Error:
thread 'main' panicked at input/code.rs:39:31:
index out of bounds: the len is 1000 but the index is 1001
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

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
(empty)

Error:
thread 'main' panicked at input/code.rs:39:31:
index out of bounds: the len is 1000 but the index is 1001
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

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
500
1 1517
3 1775
5 1706
7 1896
...

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
500
1 1517
3 1775
5 1706
7 1896
...

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
2500
1 9805
3 8159
5 5639
7 538
...

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
2500
1 9805
3 8159
5 5639
7 538
...