結果

問題 No.1861 Required Number
ユーザー phsplsphspls
提出日時 2022-10-09 12:05:22
言語 Rust
(1.77.0)
結果
AC  
実行時間 106 ms / 2,500 ms
コード長 1,083 bytes
コンパイル時間 8,426 ms
コンパイル使用メモリ 139,776 KB
実行使用メモリ 22,532 KB
最終ジャッジ日時 2023-09-05 16:49:34
合計ジャッジ時間 11,546 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 106 ms
22,532 KB
testcase_04 AC 106 ms
22,528 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,380 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 1 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 36 ms
8,752 KB
testcase_25 AC 90 ms
19,536 KB
testcase_26 AC 16 ms
5,044 KB
testcase_27 AC 33 ms
8,472 KB
testcase_28 AC 38 ms
9,596 KB
testcase_29 AC 23 ms
6,432 KB
testcase_30 AC 6 ms
4,380 KB
testcase_31 AC 93 ms
19,740 KB
testcase_32 AC 10 ms
4,380 KB
testcase_33 AC 64 ms
14,192 KB
testcase_34 AC 75 ms
16,360 KB
testcase_35 AC 78 ms
16,576 KB
testcase_36 AC 24 ms
6,684 KB
testcase_37 AC 37 ms
9,244 KB
testcase_38 AC 77 ms
16,896 KB
testcase_39 AC 43 ms
10,292 KB
testcase_40 AC 91 ms
19,792 KB
testcase_41 AC 87 ms
18,720 KB
testcase_42 AC 70 ms
15,492 KB
testcase_43 AC 38 ms
9,220 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 {
                if !dp[pat][i][j] { continue; }
                dp[pat][i+1][j] = true;
                if j + a[i] <= k {
                    dp[pat][i+1][j+a[i]] = true;
                }
            }
        }
        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