結果

問題 No.2560 A_1 < A_2 < ... < A_N
ユーザー あさくちあさくち
提出日時 2023-12-02 14:57:38
言語 Rust
(1.77.0)
結果
AC  
実行時間 120 ms / 2,000 ms
コード長 1,261 bytes
コンパイル時間 961 ms
コンパイル使用メモリ 184,640 KB
実行使用メモリ 9,984 KB
最終ジャッジ日時 2023-12-02 14:57:44
合計ジャッジ時間 3,027 ms
ジャッジサーバーID
(参考情報)
judge10 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,676 KB
testcase_01 AC 19 ms
7,168 KB
testcase_02 AC 21 ms
8,120 KB
testcase_03 AC 20 ms
9,984 KB
testcase_04 AC 23 ms
9,032 KB
testcase_05 AC 25 ms
9,344 KB
testcase_06 AC 119 ms
6,676 KB
testcase_07 AC 118 ms
6,676 KB
testcase_08 AC 120 ms
6,676 KB
testcase_09 AC 120 ms
6,676 KB
testcase_10 AC 120 ms
6,676 KB
testcase_11 AC 1 ms
6,676 KB
testcase_12 AC 1 ms
6,676 KB
testcase_13 AC 1 ms
6,676 KB
testcase_14 AC 1 ms
6,676 KB
testcase_15 AC 1 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

fn main() {
    let t = input_value();

    for _ in 0..t {
        let (n, x) = input_tuple();

        let mut total = 0_usize;

        for i in 1..=n {
            total += i;
        }

        if total > x {
            println!("-1");
            continue;
        }

        let mut list: Vec<_> = (1..=n).collect();

        list[n - 1] += x - total;

        let text = list
            .iter()
            .map(|x| x.to_string())
            .collect::<Vec<_>>()
            .join(" ");

        println!("{}", text);
    }
}

fn input_value<T>() -> T
where
    T: std::str::FromStr,
    <T as std::str::FromStr>::Err: std::fmt::Debug,
{
    let stdin = std::io::stdin();

    let mut buf = String::new();
    stdin.read_line(&mut buf).unwrap();
    buf = buf.trim_end().to_owned();

    let n = buf.parse().unwrap();

    n
}

fn input_tuple<T>() -> (T, T)
where
    T: std::str::FromStr,
    <T as std::str::FromStr>::Err: std::fmt::Debug,
{
    let stdin = std::io::stdin();

    let mut buf = String::new();
    stdin.read_line(&mut buf).unwrap();
    buf = buf.trim_end().to_owned();

    let mut iter = buf.split_whitespace();

    let n = iter.next().unwrap().parse().unwrap();
    let m = iter.next().unwrap().parse().unwrap();

    (n, m)
}
0