結果

問題 No.733 分身並列コーディング
ユーザー snteasntea
提出日時 2018-09-29 17:27:07
言語 Rust
(1.77.0)
結果
AC  
実行時間 148 ms / 1,500 ms
コード長 3,172 bytes
コンパイル時間 1,096 ms
コンパイル使用メモリ 169,820 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-20 12:54:14
合計ジャッジ時間 3,461 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 148 ms
5,376 KB
testcase_04 AC 148 ms
5,376 KB
testcase_05 AC 11 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 29 ms
5,376 KB
testcase_08 AC 20 ms
5,376 KB
testcase_09 AC 38 ms
5,376 KB
testcase_10 AC 5 ms
5,376 KB
testcase_11 AC 5 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 22 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 1 ms
5,376 KB
testcase_17 AC 0 ms
5,376 KB
testcase_18 AC 3 ms
5,376 KB
testcase_19 AC 44 ms
5,376 KB
testcase_20 AC 31 ms
5,376 KB
testcase_21 AC 23 ms
5,376 KB
testcase_22 AC 81 ms
5,376 KB
testcase_23 AC 18 ms
5,376 KB
testcase_24 AC 13 ms
5,376 KB
testcase_25 AC 1 ms
5,376 KB
testcase_26 AC 1 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 21 ms
5,376 KB
testcase_29 AC 46 ms
5,376 KB
testcase_30 AC 47 ms
5,376 KB
testcase_31 AC 47 ms
5,376 KB
testcase_32 AC 5 ms
5,376 KB
testcase_33 AC 5 ms
5,376 KB
testcase_34 AC 6 ms
5,376 KB
testcase_35 AC 5 ms
5,376 KB
testcase_36 AC 5 ms
5,376 KB
testcase_37 AC 5 ms
5,376 KB
testcase_38 AC 38 ms
5,376 KB
testcase_39 AC 38 ms
5,376 KB
testcase_40 AC 37 ms
5,376 KB
testcase_41 AC 5 ms
5,376 KB
testcase_42 AC 6 ms
5,376 KB
testcase_43 AC 5 ms
5,376 KB
testcase_44 AC 37 ms
5,376 KB
testcase_45 AC 38 ms
5,376 KB
testcase_46 AC 39 ms
5,376 KB
testcase_47 AC 38 ms
5,376 KB
testcase_48 AC 38 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused macro definition: `printf`
  --> main.rs:79:18
   |
79 |     macro_rules! printf { ($($arg:tt)*) => (write!(out, $($arg)*).unwrap()); }
   |                  ^^^^^^
   |
   = note: `#[warn(unused_macros)]` on by default

warning: unused variable: `i`
   --> main.rs:103:9
    |
103 |     for i in 0.. {
    |         ^ help: if this is intentional, prefix it with an underscore: `_i`
    |
    = note: `#[warn(unused_variables)]` on by default

warning: variable does not need to be mutable
  --> main.rs:8:13
   |
8  |           let mut s = {
   |               ----^
   |               |
   |               help: remove this `mut`
...
82 | /     input! {
83 | |         ti: usize,
84 | |         n: usize,
85 | |         t: [usize; n],
86 | |     }
   | |_____- in this macro invocation
   |
   = note: `#[warn(unused_mut)]` on by default
   = note: this warning originates in the macro `input` (in Nightly builds, run with -Z macro-backtrace for more info)

warning: 3 warnings emitted

ソースコード

diff #

// from 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 mut 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, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug { ($x: expr) => { println!("{}: {:?}", stringify!($x), $x) } }
// macro_rules! debug { ($x: expr) => () }

#[allow(dead_code)]
fn show<T>(iter: T) -> String
where
    T: Iterator,
    T::Item: std::fmt::Display
{
    let mut res = iter.fold(String::new(), |sum, e| sum + &format!("{} ", e));
    res.pop();
    res
}

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::collections::btree_map::Entry::{Occupied, Vacant};
#[allow(unused_imports)]
use std::mem::swap;

fn main() {
    use std::io::Write;
    let out = std::io::stdout();
    let mut out = std::io::BufWriter::new(out.lock());
    macro_rules! printf { ($($arg:tt)*) => (write!(out, $($arg)*).unwrap()); }
    macro_rules! printfln { () => (writeln!(out).unwrap()); ($($arg:tt)*) => (writeln!(out, $($arg)*).unwrap()); }
    
    input! {
        ti: usize,
        n: usize,
        t: [usize; n],
    }

    let mut ssum = vec![0; 1<<n];
    for mask in 1..1<<n {
        for i in 0..n {
            if (mask>>i)&1 == 1 {
                ssum[mask] = ssum[mask^(1<<i)]+t[i];
                break;
            }
        }
    }


    let inf = 1_000_000_000;
    let mut dp = vec![false; 1<<n];
    dp[0] = true;
    let mut ans = 0;
    for i in 0.. {
        // debug!(i);
        ans += 1;
        let mut nex = vec![inf; 1<<n];
        for mask in 0..1<<n {
            if dp[mask] {
                nex[mask] = 0;
            }
            for k in 0..n {
                if (mask>>k)&1 == 1 {
                    nex[mask] = min(nex[mask], nex[mask^(1<<k)]+t[k]);
                }
            }
        }
        // debug!(nex);
        dp = nex.into_iter().map(|e| e <= ti).collect();
        if dp[(1<<n)-1] {
            break;
        }
    }

    printfln!("{}", ans);   
}
0