結果

問題 No.733 分身並列コーディング
ユーザー hatoohatoo
提出日時 2018-09-30 14:15:58
言語 Rust
(1.72.1)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 3,852 bytes
コンパイル時間 2,946 ms
コンパイル使用メモリ 154,388 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-02 13:30:14
合計ジャッジ時間 30,882 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1,215 ms
4,376 KB
testcase_04 AC 1,207 ms
4,376 KB
testcase_05 AC 11 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1,357 ms
4,380 KB
testcase_08 AC 1,178 ms
4,380 KB
testcase_09 AC 426 ms
4,376 KB
testcase_10 AC 19 ms
4,380 KB
testcase_11 AC 17 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 141 ms
4,380 KB
testcase_15 AC 7 ms
4,380 KB
testcase_16 AC 1 ms
4,384 KB
testcase_17 AC 1 ms
4,384 KB
testcase_18 AC 20 ms
4,376 KB
testcase_19 AC 418 ms
4,380 KB
testcase_20 AC 442 ms
4,380 KB
testcase_21 AC 142 ms
4,380 KB
testcase_22 AC 1,300 ms
4,380 KB
testcase_23 AC 148 ms
4,380 KB
testcase_24 AC 156 ms
4,376 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 7 ms
4,380 KB
testcase_28 AC 1,219 ms
4,380 KB
testcase_29 AC 1,430 ms
4,380 KB
testcase_30 AC 1,430 ms
4,380 KB
testcase_31 AC 1,434 ms
4,376 KB
testcase_32 AC 59 ms
4,376 KB
testcase_33 AC 57 ms
4,380 KB
testcase_34 AC 59 ms
4,376 KB
testcase_35 AC 58 ms
4,380 KB
testcase_36 AC 58 ms
4,380 KB
testcase_37 AC 58 ms
4,380 KB
testcase_38 AC 1,461 ms
4,376 KB
testcase_39 AC 1,481 ms
4,384 KB
testcase_40 AC 1,462 ms
4,380 KB
testcase_41 AC 58 ms
4,380 KB
testcase_42 AC 58 ms
4,380 KB
testcase_43 AC 56 ms
4,376 KB
testcase_44 AC 1,490 ms
4,384 KB
testcase_45 TLE -
testcase_46 TLE -
testcase_47 TLE -
testcase_48 AC 1,492 ms
4,380 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;
    }
    if cache[p] {
        return 1;
    }

    let mut sub = p;
    let mut mini = 17;
    while {
        if sub != 0 && sub != p {
            mini = min(
                mini,
                rec(sub, xs, cache, memo) + 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