Submission #69085859


Source Code Expand

use std::collections::BTreeSet;

use proconio::input;

fn main() {
    input! {
        n: usize,
        st: [(u32, u32); n],
    };

    let mut left = BTreeSet::new();
    let mut right = BTreeSet::new();
    for &(s, t) in &st {
        if s > t {
            left.insert(t);
        }
        if s < t {
            right.insert(s);
        }
    }

    for &(s, t) in &st {
        if s > t {
            if right.range(t..s).next().is_some() {
                println!("No");
                return;
            }
        }
        if s < t {
            if left.range(s..t).next().is_some() {
                println!("No");
                return;
            }
        }
    }

    let mut left = Vec::new();
    let mut right = Vec::new();
    for (i, &(s, t)) in st.iter().enumerate() {
        if s > t {
            left.push((i, s, t));
        }
        if s < t {
            right.push((i, s, t));
        }
    }

    let mut ans = Vec::new();

    left.sort_unstable_by_key(|&(_, _, t)| t);
    let mut r = 0;
    for (i, s, _) in left {
        if s < r {
            println!("No");
            return;
        }
        ans.push(i);
        r = s;
    }

    right.sort_unstable_by_key(|&(_, _, t)| t);
    let mut l = u32::MAX;
    for &(i, s, _) in right.iter().rev() {
        if l < s {
            println!("No");
            return;
        }
        ans.push(i);
        l = s;
    }

    println!("Yes");
    println!(
        "{}",
        ans.iter()
            .map(|x| (x + 1).to_string())
            .collect::<Vec<_>>()
            .join(" ")
    );
}

Submission Info

Submission Time
Task C - No Collision Moves
User ikd
Language Rust (rustc 1.70.0)
Score 600
Code Size 1670 Byte
Status AC
Exec Time 83 ms
Memory 25948 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
AC × 3
AC × 27
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_handmade_00.txt, 01_handmade_01.txt, 01_handmade_02.txt, 01_handmade_03.txt, 01_handmade_04.txt, 01_handmade_05.txt, 01_handmade_06.txt, 01_handmade_07.txt, 02_random_00.txt, 02_random_01.txt, 02_random_02.txt, 02_random_03.txt, 02_random_04.txt, 02_random_05.txt, 02_random_06.txt, 02_random_07.txt, 02_random_08.txt, 02_random_09.txt, 02_random_10.txt, 02_random_11.txt, 02_random_12.txt, 02_random_13.txt, 02_random_14.txt, 02_random_15.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 2004 KiB
00_sample_01.txt AC 1 ms 1956 KiB
00_sample_02.txt AC 1 ms 1836 KiB
01_handmade_00.txt AC 1 ms 1920 KiB
01_handmade_01.txt AC 1 ms 1948 KiB
01_handmade_02.txt AC 60 ms 25948 KiB
01_handmade_03.txt AC 59 ms 22944 KiB
01_handmade_04.txt AC 83 ms 24472 KiB
01_handmade_05.txt AC 45 ms 9284 KiB
01_handmade_06.txt AC 68 ms 24400 KiB
01_handmade_07.txt AC 69 ms 24384 KiB
02_random_00.txt AC 32 ms 8364 KiB
02_random_01.txt AC 5 ms 2808 KiB
02_random_02.txt AC 13 ms 4476 KiB
02_random_03.txt AC 35 ms 8840 KiB
02_random_04.txt AC 36 ms 9292 KiB
02_random_05.txt AC 35 ms 9260 KiB
02_random_06.txt AC 35 ms 9240 KiB
02_random_07.txt AC 36 ms 9096 KiB
02_random_08.txt AC 18 ms 7708 KiB
02_random_09.txt AC 11 ms 5544 KiB
02_random_10.txt AC 59 ms 22068 KiB
02_random_11.txt AC 40 ms 15288 KiB
02_random_12.txt AC 68 ms 24036 KiB
02_random_13.txt AC 71 ms 24360 KiB
02_random_14.txt AC 69 ms 24064 KiB
02_random_15.txt AC 67 ms 23400 KiB