結果

問題 No.5 数字のブロック
ユーザー mottodoramottodora
提出日時 2016-10-18 12:30:48
言語 Rust
(1.77.0)
結果
AC  
実行時間 197 ms / 5,000 ms
コード長 953 bytes
コンパイル時間 5,808 ms
コンパイル使用メモリ 145,592 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-11 16:31:16
合計ジャッジ時間 3,846 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 76 ms
4,380 KB
testcase_04 AC 11 ms
4,380 KB
testcase_05 AC 121 ms
4,380 KB
testcase_06 AC 51 ms
4,380 KB
testcase_07 AC 36 ms
4,384 KB
testcase_08 AC 61 ms
4,380 KB
testcase_09 AC 9 ms
4,380 KB
testcase_10 AC 120 ms
4,380 KB
testcase_11 AC 30 ms
4,384 KB
testcase_12 AC 80 ms
4,384 KB
testcase_13 AC 105 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,384 KB
testcase_16 AC 125 ms
4,380 KB
testcase_17 AC 176 ms
4,380 KB
testcase_18 AC 139 ms
4,384 KB
testcase_19 AC 197 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,384 KB
testcase_22 AC 1 ms
4,384 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 1 ms
4,384 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 1 ms
4,384 KB
testcase_29 AC 10 ms
4,380 KB
testcase_30 AC 10 ms
4,380 KB
testcase_31 AC 1 ms
4,384 KB
testcase_32 AC 1 ms
4,384 KB
testcase_33 AC 1 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

fn getline() -> String{
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok();
    ret
}

fn getvec(string: String) -> Vec<i32> {
    string.trim().split_whitespace()
        .map(|s| s.parse().unwrap())
        .collect()
}

fn bubblesort(v: &Vec<i32>) -> Vec<i32> {
    let mut dst = v.to_owned();
    for i in 0..dst.len() {
        for j in i..dst.len() {
            if dst[i] > dst[j] {
                dst.swap(i, j)
            }
        }
    }
    dst
}

fn solve(v: &Vec<i32>, l: i32) -> usize {
    let sorted = bubblesort(v);
    let mut acc = 0;
    for (i, a) in sorted.into_iter().enumerate() {
        acc += a;
        if acc > l {
            return i
        }
        else if acc == l {
            return i+1
        }
    }
    v.len()
}



fn main() {
    let l:i32 = getline().trim().parse().unwrap();
    let _:i32 = getline().trim().parse().unwrap();
    println!("{}", solve(&getvec(getline()), l))
}
0