Submission #3750641


Source Code Expand

use std::cmp;

fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { reader: s.lock() };
    let n: usize = sc.read();
    let a: usize = sc.read();
    let b: usize = sc.read();
    if a + b > n + 1 || a < (n + b - 1) / b {
        println!("-1");
        return;
    }
    let mut ans = vec![];
    let mut cur = 0;
    if n % b != 0 {
        ans.push(vec![]);
        for _ in 0..(n % b) {
            ans[0].push(cur);
            cur += 1;
        }
        ans[0].reverse();
    }
    for _ in 0..(n / b) {
        let mut lds = vec![];
        for _ in 0..b {
            lds.push(cur);
            cur += 1;
        }
        lds.reverse();
        ans.push(lds);
    }
    assert_eq!(cur, n);

    let mut a = a - ans.len();
    for i in 0..ans.len() {
        if a > 0 {
            let len = cmp::min(a + 1, ans[i].len());
            ans[i][0..len].sort();
            a -= len - 1;
        }
    }

    for ans in ans.iter() {
        for &ans in ans.iter() {
            print!("{} ", ans + 1);
        }
    }
    println!();
}

pub struct Scanner<R> {
    reader: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .reader
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_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 E - LISDL
User kenkoooo
Language Rust (1.15.1)
Score 700
Code Size 1921 Byte
Status AC
Exec Time 69 ms
Memory 24828 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 700 / 700
Status
AC × 3
AC × 55
Set Name Test Cases
Sample s1.txt, s2.txt, s3.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, 37.txt, 38.txt, 39.txt, 40.txt, 41.txt, 42.txt, 43.txt, 44.txt, 45.txt, 46.txt, 47.txt, 48.txt, 49.txt, 50.txt, 51.txt, 52.txt, s1.txt, s2.txt, s3.txt
Case Name Status Exec Time Memory
01.txt AC 19 ms 4860 KB
02.txt AC 4 ms 4352 KB
03.txt AC 27 ms 7292 KB
04.txt AC 3 ms 4352 KB
05.txt AC 69 ms 24828 KB
06.txt AC 2 ms 4352 KB
07.txt AC 2 ms 4352 KB
08.txt AC 24 ms 5116 KB
09.txt AC 34 ms 7292 KB
10.txt AC 50 ms 10108 KB
11.txt AC 51 ms 10236 KB
12.txt AC 56 ms 10492 KB
13.txt AC 44 ms 7932 KB
14.txt AC 40 ms 7676 KB
15.txt AC 15 ms 4732 KB
16.txt AC 52 ms 10236 KB
17.txt AC 2 ms 4352 KB
18.txt AC 19 ms 4860 KB
19.txt AC 37 ms 7676 KB
20.txt AC 2 ms 4352 KB
21.txt AC 19 ms 4860 KB
22.txt AC 41 ms 7804 KB
23.txt AC 37 ms 7676 KB
24.txt AC 2 ms 4352 KB
25.txt AC 69 ms 24828 KB
26.txt AC 2 ms 4352 KB
27.txt AC 2 ms 4352 KB
28.txt AC 20 ms 4988 KB
29.txt AC 47 ms 9852 KB
30.txt AC 46 ms 7932 KB
31.txt AC 33 ms 7420 KB
32.txt AC 56 ms 10492 KB
33.txt AC 52 ms 10236 KB
34.txt AC 47 ms 8060 KB
35.txt AC 19 ms 4860 KB
36.txt AC 53 ms 10236 KB
37.txt AC 3 ms 4352 KB
38.txt AC 21 ms 4988 KB
39.txt AC 40 ms 7676 KB
40.txt AC 2 ms 4352 KB
41.txt AC 2 ms 4352 KB
42.txt AC 2 ms 4352 KB
43.txt AC 2 ms 4352 KB
44.txt AC 2 ms 4352 KB
45.txt AC 49 ms 10108 KB
46.txt AC 24 ms 7164 KB
47.txt AC 2 ms 4352 KB
48.txt AC 46 ms 7932 KB
49.txt AC 7 ms 4476 KB
50.txt AC 2 ms 4352 KB
51.txt AC 2 ms 4352 KB
52.txt AC 2 ms 4352 KB
s1.txt AC 2 ms 4352 KB
s2.txt AC 2 ms 4352 KB
s3.txt AC 2 ms 4352 KB