結果

問題 No.1861 Required Number
ユーザー phsplsphspls
提出日時 2022-10-23 13:06:58
言語 Rust
(1.77.0)
結果
AC  
実行時間 154 ms / 2,500 ms
コード長 1,053 bytes
コンパイル時間 1,093 ms
コンパイル使用メモリ 144,596 KB
実行使用メモリ 22,532 KB
最終ジャッジ日時 2023-09-15 00:01:38
合計ジャッジ時間 9,770 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 154 ms
22,492 KB
testcase_04 AC 153 ms
22,532 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 41 ms
8,756 KB
testcase_25 AC 101 ms
19,508 KB
testcase_26 AC 18 ms
5,092 KB
testcase_27 AC 37 ms
8,516 KB
testcase_28 AC 43 ms
9,288 KB
testcase_29 AC 25 ms
6,420 KB
testcase_30 AC 7 ms
4,380 KB
testcase_31 AC 103 ms
19,784 KB
testcase_32 AC 10 ms
4,376 KB
testcase_33 AC 71 ms
14,160 KB
testcase_34 AC 83 ms
16,344 KB
testcase_35 AC 85 ms
16,608 KB
testcase_36 AC 27 ms
6,680 KB
testcase_37 AC 42 ms
9,232 KB
testcase_38 AC 87 ms
16,872 KB
testcase_39 AC 49 ms
10,280 KB
testcase_40 AC 104 ms
19,704 KB
testcase_41 AC 97 ms
18,692 KB
testcase_42 AC 80 ms
15,548 KB
testcase_43 AC 43 ms
9,232 KB
testcase_44 AC 1 ms
4,376 KB
04_evil_1.txt MLE -
04_evil_2.txt MLE -
04_evil_3.txt MLE -
04_evil_4.txt MLE -
権限があれば一括ダウンロードができます

ソースコード

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 = String::new();
    std::io::stdin().read_line(&mut a).ok();
    let mut a: Vec<usize> = a.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();

    let mut dp = vec![vec![vec![false; k+1]; n+2]; 2];
    dp[0][0][0] = true;
    dp[1][0][0] = true;
    for pat in 0..2 {
        for i in 0..n {
            for j in 0..=k {
                dp[pat][i+1][j] |= dp[pat][i][j];
                if j+a[i] <= k {
                    dp[pat][i+1][j+a[i]] |= dp[pat][i][j];
                }
            }
        }
        a.reverse();
    }
    dp[1].reverse();
    if !dp[0][n][k] {
        println!("-1");
        return;
    }
    let mut result = 0usize;
    for i in 0..n {
        if !(0..=k).any(|j| dp[0][i][j] && dp[1][i+2][k-j]) {
            result += 1;
        }
    }
    println!("{}", result);
}
0