結果

問題 No.617 Nafmo、買い出しに行く
ユーザー phsplsphspls
提出日時 2020-02-21 21:05:05
言語 Rust
(1.72.1)
結果
AC  
実行時間 179 ms / 2,000 ms
コード長 812 bytes
コンパイル時間 1,121 ms
コンパイル使用メモリ 144,480 KB
実行使用メモリ 42,940 KB
最終ジャッジ日時 2023-07-30 05:02:48
合計ジャッジ時間 3,190 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
5,012 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 18 ms
6,044 KB
testcase_03 AC 49 ms
13,120 KB
testcase_04 AC 4 ms
4,380 KB
testcase_05 AC 86 ms
21,684 KB
testcase_06 AC 178 ms
42,936 KB
testcase_07 AC 179 ms
42,940 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 127 ms
31,168 KB
testcase_11 AC 154 ms
37,156 KB
testcase_12 AC 81 ms
20,824 KB
testcase_13 AC 50 ms
13,224 KB
testcase_14 AC 65 ms
16,712 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

fn main() {
    let mut nk = String::new();
    std::io::stdin().read_line(&mut nk).ok();
    let nk: Vec<usize> = nk.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let n = nk[0];
    let k = nk[1];
    let mut a: Vec<usize> = vec![];
    for _ in 0..n {
        let mut aa = String::new();
        std::io::stdin().read_line(&mut aa).ok();
        let aa: usize = aa.trim().parse().unwrap();
        a.push(aa);
    }

    let mut dp: Vec<Vec<bool>> = vec![vec![false; k+1]; n+1];
    dp[0][0] = true;
    for i in 0..n {
        for j in 0..=k {
            dp[i+1][j] |= dp[i][j];
            if a[i] <= j {
                dp[i+1][j] |= dp[i][j-a[i]];
            }
        }
    }
    println!("{}", dp[n].iter().enumerate().filter(|pair| *pair.1).map(|pair| pair.0).max().unwrap());
}
0