結果

問題 No.1861 Required Number
ユーザー phsplsphspls
提出日時 2022-09-26 23:24:00
言語 Rust
(1.77.0)
結果
AC  
実行時間 66 ms / 2,500 ms
コード長 1,154 bytes
コンパイル時間 13,245 ms
コンパイル使用メモリ 378,844 KB
実行使用メモリ 19,712 KB
最終ジャッジ日時 2024-06-02 00:30:20
合計ジャッジ時間 18,430 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
5,248 KB
testcase_01 AC 1 ms
5,248 KB
testcase_02 AC 1 ms
5,248 KB
testcase_03 AC 9 ms
5,376 KB
testcase_04 AC 8 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 0 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 AC 1 ms
5,376 KB
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 1 ms
5,376 KB
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 1 ms
5,376 KB
testcase_21 AC 1 ms
5,376 KB
testcase_22 AC 1 ms
5,376 KB
testcase_23 AC 1 ms
5,376 KB
testcase_24 AC 27 ms
8,832 KB
testcase_25 AC 65 ms
19,456 KB
testcase_26 AC 12 ms
5,376 KB
testcase_27 AC 24 ms
8,448 KB
testcase_28 AC 28 ms
9,600 KB
testcase_29 AC 16 ms
6,400 KB
testcase_30 AC 4 ms
5,376 KB
testcase_31 AC 66 ms
19,712 KB
testcase_32 AC 8 ms
5,376 KB
testcase_33 AC 50 ms
14,080 KB
testcase_34 AC 52 ms
16,256 KB
testcase_35 AC 55 ms
16,640 KB
testcase_36 AC 18 ms
6,656 KB
testcase_37 AC 27 ms
9,216 KB
testcase_38 AC 54 ms
16,768 KB
testcase_39 AC 30 ms
10,240 KB
testcase_40 AC 65 ms
19,584 KB
testcase_41 AC 65 ms
18,560 KB
testcase_42 AC 52 ms
15,616 KB
testcase_43 AC 28 ms
9,344 KB
testcase_44 AC 0 ms
5,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`
 --> src/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

ソースコード

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];
    for pat in 0..2 {
        dp[pat][0][0] = true;
        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