Submission #9311532


Source Code Expand

fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());

    let n: usize = sc.read();
    let mut x = vec![];
    for i in 0..n {
        let a: usize = sc.read();
        x.push((a, i));
    }
    x.sort();

    let mut ans = vec![None; n * n];
    let mut hole_head = 0;
    let mut cur_sum = 0;
    for &(x, i) in x.iter() {
        let lower_count = i + 1;
        if cur_sum + lower_count > x {
            println!("No");
            return;
        }
        cur_sum += lower_count;
        ans[x - 1] = Some(i + 1);
        for _ in 1..lower_count {
            while ans[hole_head].is_some() {
                hole_head += 1;
                if hole_head >= n * n {
                    println!("No");
                    return;
                }
            }
            ans[hole_head] = Some(i + 1);
            hole_head += 1;
        }
    }

    let mut hole_tail = n * n - 1;
    let mut cur_sum = 0;
    for &(x, i) in x.iter().rev() {
        let upper_count = n - (i + 1);
        if cur_sum + upper_count > n * n - x {
            println!("No");
            return;
        }
        cur_sum += upper_count;
        for _ in 0..upper_count {
            while ans[hole_tail].is_some() {
                if hole_tail == 0 {
                    println!("No");
                    return;
                }
                hole_tail -= 1;
            }
            if hole_tail <= x - 1 {
                println!("No");
                return;
            }
            ans[hole_tail] = Some(i + 1);
        }
    }

    println!("Yes");
    for ans in ans.into_iter() {
        print!("{} ", ans.unwrap());
    }
    println!();
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: std::ops::Deref<Target = str>>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}

Submission Info

Submission Time
Task D - K-th K
User kenkoooo
Language Rust (1.15.1)
Score 800
Code Size 2920 Byte
Status AC
Exec Time 41 ms
Memory 9340 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 800 / 800
Status
AC × 2
AC × 49
Set Name Test Cases
Sample 0_00.txt, 0_01.txt
All 0_00.txt, 0_01.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt, 1_08.txt, 1_09.txt, 1_10.txt, 1_11.txt, 1_12.txt, 1_13.txt, 1_14.txt, 1_15.txt, 1_16.txt, 1_17.txt, 1_18.txt, 1_19.txt, 1_20.txt, 1_21.txt, 1_22.txt, 1_23.txt, 1_24.txt, 1_25.txt, 1_26.txt, 1_27.txt, 1_28.txt, 1_29.txt, 1_30.txt, 1_31.txt, 1_32.txt, 1_33.txt, 1_34.txt, 1_35.txt, 1_36.txt, 1_37.txt, 1_38.txt, 1_39.txt, 1_40.txt, 1_41.txt, 1_42.txt, 1_43.txt, 1_44.txt, 1_45.txt, 1_46.txt
Case Name Status Exec Time Memory
0_00.txt AC 2 ms 4352 KiB
0_01.txt AC 2 ms 4352 KiB
1_00.txt AC 2 ms 4352 KiB
1_01.txt AC 40 ms 9340 KiB
1_02.txt AC 40 ms 9340 KiB
1_03.txt AC 40 ms 9340 KiB
1_04.txt AC 40 ms 9340 KiB
1_05.txt AC 40 ms 9340 KiB
1_06.txt AC 40 ms 9340 KiB
1_07.txt AC 41 ms 9340 KiB
1_08.txt AC 40 ms 9340 KiB
1_09.txt AC 3 ms 8444 KiB
1_10.txt AC 3 ms 8444 KiB
1_11.txt AC 3 ms 8444 KiB
1_12.txt AC 3 ms 8444 KiB
1_13.txt AC 3 ms 8444 KiB
1_14.txt AC 3 ms 8444 KiB
1_15.txt AC 28 ms 9084 KiB
1_16.txt AC 3 ms 8444 KiB
1_17.txt AC 3 ms 8444 KiB
1_18.txt AC 36 ms 9212 KiB
1_19.txt AC 38 ms 9212 KiB
1_20.txt AC 30 ms 9084 KiB
1_21.txt AC 37 ms 9212 KiB
1_22.txt AC 33 ms 9212 KiB
1_23.txt AC 3 ms 8444 KiB
1_24.txt AC 36 ms 9212 KiB
1_25.txt AC 29 ms 9084 KiB
1_26.txt AC 3 ms 8444 KiB
1_27.txt AC 3 ms 8444 KiB
1_28.txt AC 3 ms 8444 KiB
1_29.txt AC 3 ms 8444 KiB
1_30.txt AC 35 ms 9212 KiB
1_31.txt AC 38 ms 9340 KiB
1_32.txt AC 3 ms 8444 KiB
1_33.txt AC 37 ms 9212 KiB
1_34.txt AC 3 ms 8444 KiB
1_35.txt AC 3 ms 8444 KiB
1_36.txt AC 36 ms 9212 KiB
1_37.txt AC 35 ms 9212 KiB
1_38.txt AC 40 ms 9340 KiB
1_39.txt AC 3 ms 8444 KiB
1_40.txt AC 17 ms 6652 KiB
1_41.txt AC 3 ms 8444 KiB
1_42.txt AC 25 ms 8956 KiB
1_43.txt AC 35 ms 9212 KiB
1_44.txt AC 3 ms 8444 KiB
1_45.txt AC 3 ms 8444 KiB
1_46.txt AC 3 ms 8444 KiB