結果

問題 No.1560 majority x majority
ユーザー fukafukatanifukafukatani
提出日時 2021-06-25 23:18:04
言語 Rust
(1.77.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,584 bytes
コンパイル時間 1,034 ms
コンパイル使用メモリ 155,888 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-07 15:02:18
合計ジャッジ時間 12,921 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 AC 1,312 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 707 ms
4,380 KB
testcase_04 AC 385 ms
4,380 KB
testcase_05 AC 697 ms
4,376 KB
testcase_06 AC 120 ms
4,380 KB
testcase_07 AC 21 ms
4,380 KB
testcase_08 AC 723 ms
4,376 KB
testcase_09 AC 273 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 30 ms
4,380 KB
testcase_12 AC 5 ms
4,380 KB
testcase_13 AC 41 ms
4,376 KB
testcase_14 AC 4 ms
4,380 KB
testcase_15 AC 199 ms
4,384 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 924 ms
4,380 KB
testcase_18 AC 135 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 341 ms
4,376 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 288 ms
4,380 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;
use std::ops::Bound::*;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<usize>();
    let (n, m) = (v[0], v[1]);
    let mut s = vec![vec![]; n];
    for i in 0..n {
        s[i] = read_vec::<i32>();
    }

    let mut dp = vec![0i64; 1 << m];
    dp[0] = 1;
    for state in 0..1 << m {
        let accepted = (0..m).map(|x| (state >> x) & 1 == 1).collect::<Vec<_>>();
        for next_plan in 0..m {
            if accepted[next_plan] {
                continue;
            }

            let mut total = 0;
            let mut agreed = 0;
            for i in 0..n {
                if (0..m).any(|j| accepted[j] && s[i][j] == 0) {
                    continue;
                }
                total += 1;
                agreed += s[i][next_plan];
            }
            if agreed * 2 >= total {
                dp[state | (1 << next_plan)] += dp[state];
            }
        }
    }
    println!("{}", dp[(1 << m) - 1]);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
0