結果

問題 No.1861 Required Number
ユーザー akakimidoriakakimidori
提出日時 2022-03-04 21:31:23
言語 Rust
(1.77.0 + proconio)
結果
AC  
実行時間 114 ms / 2,500 ms
コード長 2,936 bytes
コンパイル時間 13,893 ms
コンパイル使用メモリ 396,168 KB
実行使用メモリ 13,888 KB
最終ジャッジ日時 2024-07-18 22:28:15
合計ジャッジ時間 30,201 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
13,752 KB
testcase_01 AC 1 ms
10,012 KB
testcase_02 AC 1 ms
13,884 KB
testcase_03 AC 110 ms
10,272 KB
testcase_04 AC 114 ms
13,884 KB
testcase_05 AC 0 ms
10,528 KB
testcase_06 AC 1 ms
13,888 KB
testcase_07 AC 0 ms
6,944 KB
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 1 ms
6,940 KB
testcase_10 AC 1 ms
6,944 KB
testcase_11 AC 1 ms
6,940 KB
testcase_12 AC 1 ms
6,940 KB
testcase_13 AC 1 ms
6,940 KB
testcase_14 AC 1 ms
6,940 KB
testcase_15 AC 1 ms
6,944 KB
testcase_16 AC 1 ms
6,940 KB
testcase_17 AC 1 ms
6,944 KB
testcase_18 AC 1 ms
6,944 KB
testcase_19 AC 1 ms
6,940 KB
testcase_20 AC 1 ms
6,940 KB
testcase_21 AC 0 ms
6,940 KB
testcase_22 AC 1 ms
6,940 KB
testcase_23 AC 1 ms
6,940 KB
testcase_24 AC 19 ms
6,944 KB
testcase_25 AC 50 ms
6,944 KB
testcase_26 AC 8 ms
6,940 KB
testcase_27 AC 18 ms
6,940 KB
testcase_28 AC 21 ms
6,940 KB
testcase_29 AC 13 ms
6,944 KB
testcase_30 AC 4 ms
6,940 KB
testcase_31 AC 51 ms
6,944 KB
testcase_32 AC 6 ms
6,940 KB
testcase_33 AC 34 ms
6,940 KB
testcase_34 AC 41 ms
6,940 KB
testcase_35 AC 42 ms
6,940 KB
testcase_36 AC 13 ms
6,944 KB
testcase_37 AC 21 ms
6,944 KB
testcase_38 AC 41 ms
6,940 KB
testcase_39 AC 24 ms
6,944 KB
testcase_40 AC 49 ms
6,944 KB
testcase_41 AC 46 ms
6,940 KB
testcase_42 AC 38 ms
6,944 KB
testcase_43 AC 21 ms
6,944 KB
testcase_44 AC 1 ms
6,944 KB
04_evil_1.txt TLE -
04_evil_2.txt TLE -
04_evil_3.txt TLE -
04_evil_4.txt TLE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused import: `std::io::Write`
  --> src/main.rs:67:5
   |
67 | use std::io::Write;
   |     ^^^^^^^^^^^^^^
   |
   = note: `#[warn(unused_imports)]` on by default

warning: function `rand_memory` is never used
 --> src/main.rs:1:4
  |
1 | fn rand_memory() -> usize {
  |    ^^^^^^^^^^^
  |
  = note: `#[warn(dead_code)]` on by default

warning: function `rand` is never used
 --> src/main.rs:5:4
  |
5 | fn rand() -> usize {
  |    ^^^^

warning: type alias `Map` is never used
  --> src/main.rs:70:6
   |
70 | type Map<K, V> = BTreeMap<K, V>;
   |      ^^^

warning: type alias `Set` is never used
  --> src/main.rs:71:6
   |
71 | type Set<T> = BTreeSet<T>;
   |      ^^^

warning: type alias `Deque` is never used
  --> src/main.rs:72:6
   |
72 | type Deque<T> = VecDeque<T>;
   |      ^^^^^

ソースコード

diff #

fn rand_memory() -> usize {
    Box::into_raw(Box::new("I hope this is a random number")) as usize
}

fn rand() -> usize {
    static mut X: usize = 0;
    unsafe {
        if X == 0 {
            X = rand_memory();
        }
        X ^= X << 13;
        X ^= X >> 17;
        X ^= X << 5;
        X
    }
}
// ---------- begin input macro ----------
// reference: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, bytes) => {
        read_value!($iter, String).bytes().collect::<Vec<u8>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
// ---------- end input macro ----------

use std::io::Write;
use std::collections::*;

type Map<K, V> = BTreeMap<K, V>;
type Set<T> = BTreeSet<T>;
type Deque<T> = VecDeque<T>;

fn run() {
    input! {
        n: usize,
        k: usize,
        a: [usize; n],
    }
    let mut dp = vec![false; k + 1];
    dp[0] = true;
    let calc = |a: usize, dp: &mut [bool]| {
        for i in (a..dp.len()).rev() {
            dp[i] |= dp[i - a];
        }
    };
    let mut elem = false;
    let mut ans = 0;
    let mut dfs = vec![(a.as_slice(), dp)];
    while let Some((a, mut dp)) = dfs.pop() {
        if a.len() == 1 {
            let a = a[0];
            if a > 0 && !dp[k] && dp[k - a] {
                ans += 1;
            }
            if dp[k] {
                elem = true;
            }
            continue;
        }
        let m = a.len() / 2;
        let (l, r) = a.split_at(m);
        let save = dp.clone();
        for l in l.iter() {
            calc(*l, &mut dp);
        }
        dfs.push((r, dp));
        let mut dp = save;
        for l in r.iter() {
            calc(*l, &mut dp);
        }
        dfs.push((l, dp));
    }
    if ans == 0 && !elem {
        ans = -1;
    }
    println!("{}", ans);
}

fn main() {
    run();
}
0