結果
| 問題 |
No.1560 majority x majority
|
| コンテスト | |
| ユーザー |
fukafukatani
|
| 提出日時 | 2021-06-25 23:18:04 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
TLE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,584 bytes |
| コンパイル時間 | 13,125 ms |
| コンパイル使用メモリ | 401,028 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-06-25 08:52:07 |
| 合計ジャッジ時間 | 24,805 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 25 TLE * 1 |
ソースコード
#![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()
}
fukafukatani