結果

問題 No.733 分身並列コーディング
ユーザー hatoohatoo
提出日時 2018-09-28 20:34:33
言語 Rust
(1.77.0 + proconio)
結果
AC  
実行時間 656 ms / 1,500 ms
コード長 3,741 bytes
コンパイル時間 12,989 ms
コンパイル使用メモリ 405,504 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-10-12 05:34:49
合計ジャッジ時間 21,260 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,820 KB
testcase_01 AC 1 ms
6,820 KB
testcase_02 AC 1 ms
6,820 KB
testcase_03 AC 150 ms
6,820 KB
testcase_04 AC 149 ms
6,820 KB
testcase_05 AC 656 ms
6,816 KB
testcase_06 AC 1 ms
6,820 KB
testcase_07 AC 635 ms
6,816 KB
testcase_08 AC 647 ms
6,820 KB
testcase_09 AC 67 ms
6,816 KB
testcase_10 AC 5 ms
6,816 KB
testcase_11 AC 4 ms
6,816 KB
testcase_12 AC 1 ms
6,816 KB
testcase_13 AC 1 ms
6,816 KB
testcase_14 AC 23 ms
6,816 KB
testcase_15 AC 2 ms
6,816 KB
testcase_16 AC 2 ms
6,816 KB
testcase_17 AC 1 ms
6,816 KB
testcase_18 AC 7 ms
6,816 KB
testcase_19 AC 67 ms
6,816 KB
testcase_20 AC 84 ms
6,820 KB
testcase_21 AC 24 ms
6,816 KB
testcase_22 AC 203 ms
6,820 KB
testcase_23 AC 29 ms
6,816 KB
testcase_24 AC 39 ms
6,820 KB
testcase_25 AC 1 ms
6,820 KB
testcase_26 AC 1 ms
6,816 KB
testcase_27 AC 3 ms
6,820 KB
testcase_28 AC 610 ms
6,816 KB
testcase_29 AC 305 ms
6,816 KB
testcase_30 AC 302 ms
6,820 KB
testcase_31 AC 314 ms
6,820 KB
testcase_32 AC 19 ms
6,816 KB
testcase_33 AC 17 ms
6,816 KB
testcase_34 AC 17 ms
6,816 KB
testcase_35 AC 18 ms
6,816 KB
testcase_36 AC 18 ms
6,820 KB
testcase_37 AC 16 ms
6,816 KB
testcase_38 AC 375 ms
6,820 KB
testcase_39 AC 386 ms
6,816 KB
testcase_40 AC 402 ms
6,816 KB
testcase_41 AC 18 ms
6,824 KB
testcase_42 AC 17 ms
6,816 KB
testcase_43 AC 16 ms
6,816 KB
testcase_44 AC 392 ms
6,816 KB
testcase_45 AC 392 ms
6,816 KB
testcase_46 AC 386 ms
6,820 KB
testcase_47 AC 408 ms
6,816 KB
testcase_48 AC 396 ms
6,820 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#[doc = " https://github.com/hatoo/competitive-rust-snippets"]
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};
#[allow(unused_imports)]
use std::iter::FromIterator;
mod util {
    use std::fmt::Debug;
    use std::io::{stdin, stdout, BufWriter, StdoutLock};
    use std::str::FromStr;
    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }
    #[allow(dead_code)]
    pub fn chars() -> Vec<char> {
        line().chars().collect()
    }
    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }
    #[allow(dead_code)]
    pub fn with_bufwriter<F: FnOnce(BufWriter<StdoutLock>) -> ()>(f: F) {
        let out = stdout();
        let writer = BufWriter::new(out.lock());
        f(writer)
    }
}
#[allow(unused_macros)]
macro_rules ! get { ( $ t : ty ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . trim ( ) . parse ::<$ t > ( ) . unwrap ( ) } } ; ( $ ( $ t : ty ) ,* ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; let mut iter = line . split_whitespace ( ) ; ( $ ( iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) , ) * ) } } ; ( $ t : ty ; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ ( $ t : ty ) ,*; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ ( $ t ) ,* ) ) . collect ::< Vec < _ >> ( ) } ; ( $ t : ty ;; ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . split_whitespace ( ) . map ( | t | t . parse ::<$ t > ( ) . unwrap ( ) ) . collect ::< Vec < _ >> ( ) } } ; ( $ t : ty ;; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ t ;; ) ) . collect ::< Vec < _ >> ( ) } ; }
#[allow(unused_macros)]
macro_rules ! debug { ( $ ( $ a : expr ) ,* ) => { eprintln ! ( concat ! ( $ ( stringify ! ( $ a ) , " = {:?}, " ) ,* ) , $ ( $ a ) ,* ) ; } }
const BIG_STACK_SIZE: bool = true;
#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

fn rec(p: usize, xs: &[usize], cache: &[bool], memo: &mut [Option<usize>]) -> usize {
    if let Some(res) = memo[p] {
        return res;
    }
    if p == 0 {
        return 0;
    }

    let mut sub = p;
    let mut mini = 17;
    while {
        if sub != 0 && cache[sub] {
            mini = min(mini, 1 + rec(p ^ sub, xs, cache, memo));
        }
        sub = ((sub as isize - 1) & p as isize) as usize;
        sub != p
    } {}
    memo[p] = Some(mini);
    mini
}

fn solve() {
    let t = get!(usize);
    let n = get!(usize);
    let xs = get!(usize; n);

    let mut memo = vec![None; 1 << xs.len()];
    let mut cache = vec![false; 1 << xs.len()];
    for p in 0..1 << n {
        cache[p] = (0..xs.len())
            .filter(|&i| p >> i & 1 == 1)
            .map(|i| xs[i])
            .sum::<usize>()
            <= t;
    }
    println!("{}", rec((1 << n) - 1, &xs, &cache, &mut memo));
}
0