結果

問題 No.1861 Required Number
ユーザー phsplsphspls
提出日時 2022-09-25 19:22:23
言語 Rust
(1.77.0)
結果
AC  
実行時間 128 ms / 2,500 ms
コード長 1,357 bytes
コンパイル時間 1,017 ms
コンパイル使用メモリ 152,384 KB
実行使用メモリ 19,792 KB
最終ジャッジ日時 2023-08-24 01:46:59
合計ジャッジ時間 11,049 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 14 ms
4,380 KB
testcase_04 AC 13 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,380 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 49 ms
8,796 KB
testcase_25 AC 125 ms
19,528 KB
testcase_26 AC 22 ms
5,072 KB
testcase_27 AC 46 ms
8,540 KB
testcase_28 AC 53 ms
9,324 KB
testcase_29 AC 31 ms
6,420 KB
testcase_30 AC 8 ms
4,376 KB
testcase_31 AC 128 ms
19,792 KB
testcase_32 AC 11 ms
4,380 KB
testcase_33 AC 86 ms
14,208 KB
testcase_34 AC 102 ms
16,356 KB
testcase_35 AC 104 ms
16,532 KB
testcase_36 AC 32 ms
6,700 KB
testcase_37 AC 50 ms
9,240 KB
testcase_38 AC 105 ms
16,864 KB
testcase_39 AC 59 ms
10,268 KB
testcase_40 AC 126 ms
19,484 KB
testcase_41 AC 120 ms
18,732 KB
testcase_42 AC 97 ms
15,520 KB
testcase_43 AC 52 ms
9,192 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 -
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused variable: `n`
 --> Main.rs:6:9
  |
6 |     let n = nk[0];
  |         ^ help: if this is intentional, prefix it with an underscore: `_n`
  |
  = note: `#[warn(unused_variables)]` on by default

warning: 1 warning emitted

ソースコード

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 a: Vec<usize> = a.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();

    let mut a = a.into_iter().filter(|&v| v > 0).collect::<Vec<usize>>();
    let n = a.len();
    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();
    }
    if !dp[0][n][k] {
        println!("-1");
        return;
    }
    dp[1].reverse();
    let mut result = 0usize;
// for i in 0..2 { for j in 0..=n+1 { eprintln!("{}: {:?}", i, dp[i][j]); } }
    for i in 0..n {
        if a[i] > k { continue; }
        let mut flg = false;
        for j in 0..=k {
            flg |= dp[0][i][j] && dp[1][i+2][k-j];
        }
        if !flg {
            result += 1;
        }
    }
    println!("{}", result);
}
0