結果

問題 No.2567 A_1 > A_2 > ... > A_N
ユーザー Kyo_s_s
提出日時 2023-11-18 15:28:11
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 118 ms / 2,000 ms
コード長 1,751 bytes
コンパイル時間 13,992 ms
コンパイル使用メモリ 379,264 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2024-09-26 05:48:35
合計ジャッジ時間 16,848 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes.by_ref().map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr,) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => { ($(read_value!($next, $t)),*) };
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error"));
}

fn main() {
    input! {
        t: usize,
        query: [(usize, usize); t]
    }

    for i in 0..t {
        let (n, x) = query[i];

        if (1..=n).sum::<usize>() > x {
            println!("-1");
            continue;
        }

        let ad = (x - (1..=n).sum::<usize>()) / n;
        let mut mo = (x - (1..=n).sum::<usize>()) % n;
        let ans = (1..=n)
            .rev()
            .map(|i| {
                if mo > 0 {
                    mo -= 1;
                    i + ad + 1
                } else {
                    i + ad
                }
            })
            .collect::<Vec<_>>();

        let line = ans
            .iter()
            .map(|i| i.to_string())
            .collect::<Vec<_>>()
            .join(" ");
        println!("{}", line);
    }
}
0