結果

問題 No.2560 A_1 < A_2 < ... < A_N
ユーザー atcoder8
提出日時 2023-12-02 14:59:39
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 110 ms / 2,000 ms
コード長 987 bytes
コンパイル時間 14,670 ms
コンパイル使用メモリ 379,012 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-09-26 17:50:37
合計ジャッジ時間 16,248 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 15
権限があれば一括ダウンロードができます

ソースコード

diff #

fn main() {
    let t = {
        let mut line = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().parse::<usize>().unwrap()
    };

    for _ in 0..t {
        match solve() {
            Some(ans) => {
                print!("{}", ans[0]);
                for e in ans[1..].iter() {
                    print!(" {}", e);
                }
                println!();
            }
            None => println!("-1"),
        }
    }
}

fn solve() -> Option<Vec<usize>> {
    let (n, x) = {
        let mut line = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse::<usize>().unwrap(),
            iter.next().unwrap().parse::<usize>().unwrap(),
        )
    };

    if n * (n + 1) / 2 > x {
        return None;
    }

    let mut seq = (1..=n).collect::<Vec<usize>>();
    seq[n - 1] += x - n * (n + 1) / 2;

    Some(seq)
}
0