結果

問題 No.2560 A_1 < A_2 < ... < A_N
ユーザー kutsutamakutsutama
提出日時 2024-01-02 01:07:07
言語 Rust
(1.77.0)
結果
AC  
実行時間 138 ms / 2,000 ms
コード長 955 bytes
コンパイル時間 8,152 ms
コンパイル使用メモリ 167,888 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-01-02 01:07:19
合計ジャッジ時間 11,647 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,676 KB
testcase_01 AC 14 ms
6,676 KB
testcase_02 AC 18 ms
6,676 KB
testcase_03 AC 15 ms
6,676 KB
testcase_04 AC 17 ms
6,676 KB
testcase_05 AC 18 ms
6,676 KB
testcase_06 AC 123 ms
6,676 KB
testcase_07 AC 138 ms
6,676 KB
testcase_08 AC 122 ms
6,676 KB
testcase_09 AC 121 ms
6,676 KB
testcase_10 AC 119 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 #

use std::io;

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

    for _ in 0..t {
        let raw = input_string();
        let sp: Vec<&str> = raw.split(' ').collect();
        let n: usize = parse(&sp[0]);
        let x: usize = parse(&sp[1]);

        let mut arr: Vec<usize> = (1..=n).collect();
        let sum: usize = arr.iter().sum();
        if sum > x {
            println!("-1");
            continue;
        }
        arr[n - 1] = n + x - sum;
        print_array(&arr);
    }
}

fn input_string() -> String {
    let mut input = String::new();
    io::stdin().read_line(&mut input).unwrap();
    input
}

fn input_usize() -> usize {
    let string_input = input_string();
    parse(&string_input)
}

fn parse(string: &str) -> usize {
    string.trim().parse().unwrap()
}

fn print_array<T: std::fmt::Display>(array: &Vec<T>) {
    let mut res = String::new();
    for a in array {
        res += &format!("{} ", a);
    }
    println!("{}", res);
}
0