結果
問題 | No.2669 Generalized Hitting Set |
ユーザー | akakimidori |
提出日時 | 2024-03-08 23:39:48 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 540 ms / 4,000 ms |
コード長 | 3,914 bytes |
コンパイル時間 | 13,229 ms |
コンパイル使用メモリ | 402,044 KB |
実行使用メモリ | 91,072 KB |
最終ジャッジ日時 | 2024-09-29 20:51:20 |
合計ジャッジ時間 | 21,183 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
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 | 28 ms
12,800 KB |
testcase_04 | AC | 21 ms
10,976 KB |
testcase_05 | AC | 19 ms
9,472 KB |
testcase_06 | AC | 32 ms
15,760 KB |
testcase_07 | AC | 5 ms
6,816 KB |
testcase_08 | AC | 9 ms
6,820 KB |
testcase_09 | AC | 25 ms
10,996 KB |
testcase_10 | AC | 12 ms
6,816 KB |
testcase_11 | AC | 7 ms
6,816 KB |
testcase_12 | AC | 30 ms
13,548 KB |
testcase_13 | AC | 443 ms
67,460 KB |
testcase_14 | AC | 45 ms
10,112 KB |
testcase_15 | AC | 1 ms
6,820 KB |
testcase_16 | AC | 12 ms
6,816 KB |
testcase_17 | AC | 40 ms
10,008 KB |
testcase_18 | AC | 1 ms
6,820 KB |
testcase_19 | AC | 6 ms
6,820 KB |
testcase_20 | AC | 1 ms
6,820 KB |
testcase_21 | AC | 12 ms
6,820 KB |
testcase_22 | AC | 4 ms
6,816 KB |
testcase_23 | AC | 50 ms
20,708 KB |
testcase_24 | AC | 32 ms
14,520 KB |
testcase_25 | AC | 57 ms
19,392 KB |
testcase_26 | AC | 432 ms
69,984 KB |
testcase_27 | AC | 27 ms
11,292 KB |
testcase_28 | AC | 504 ms
91,068 KB |
testcase_29 | AC | 506 ms
91,072 KB |
testcase_30 | AC | 511 ms
89,292 KB |
testcase_31 | AC | 508 ms
88,636 KB |
testcase_32 | AC | 490 ms
84,540 KB |
testcase_33 | AC | 50 ms
18,420 KB |
testcase_34 | AC | 48 ms
18,680 KB |
testcase_35 | AC | 122 ms
31,872 KB |
testcase_36 | AC | 1 ms
6,816 KB |
testcase_37 | AC | 21 ms
6,816 KB |
testcase_38 | AC | 2 ms
6,816 KB |
testcase_39 | AC | 540 ms
84,348 KB |
testcase_40 | AC | 532 ms
84,036 KB |
ソースコード
use std::io::Write; fn run() { input! { n: usize, m: usize, k: usize, s: [bytes; m], } let mut dp = vec![0i32; 1 << n]; for s in s { let mut bit = 0usize; for (i, c) in s.iter().enumerate() { if *c == b'1' { bit |= 1 << i; } } dp[bit] += 1; } bitwise_transform(&mut dp, |a, b| *a += *b); let mut binom = vec![vec![0i32; 2 * n + 1]; 2 * n + 1]; binom[0][0] = 1; for i in 1..binom.len() { binom[i][0] = 1; for j in 1..(i + 1) { binom[i][j] = binom[i - 1][j - 1] + binom[i - 1][j]; } } let mut mul = vec![0; n + 1]; for i in k..=n { let mut sum = 0; for j in k..i { sum += binom[i][j] * mul[j]; } mul[i] = -sum + 1; } for (i, dp) in dp.iter_mut().enumerate() { let c = i.count_ones() as usize; *dp *= mul[c]; } bitwise_transform(&mut dp, |a, b| *b += *a); let mut ans = vec![n; m + 1]; for (i, dp) in dp.iter().enumerate() { let c = i.count_ones() as usize; if c >= k { ans[*dp as usize].chmin(c); } } for i in (1..m).rev() { ans[i] = ans[i].min(ans[i + 1]); } let out = std::io::stdout(); let mut out = std::io::BufWriter::new(out.lock()); for a in ans[1..].iter() { writeln!(out, "{}", *a).ok(); } } fn main() { run(); } // ---------- begin bitwise transform ---------- pub fn bitwise_transform<T, F>(a: &mut [T], mut f: F) where F: FnMut(&mut T, &mut T) { let n = a.len().trailing_zeros() as usize; assert!(a.len() == 1 << n); for i in 0..n { for a in a.chunks_exact_mut(2 << i) { let (x, y) = a.split_at_mut(1 << i); for (x, y) in x.iter_mut().zip(y) { f(x, y); } } } } // ---------- end bitwise transform ---------- // ---------- begin input macro ---------- // reference: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 #[macro_export] macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); input_inner!{iter, $($r)*} }; ($($r:tt)*) => { let 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_export] 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_export] 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, bytes) => { read_value!($iter, String).bytes().collect::<Vec<u8>>() }; ($iter:expr, usize1) => { read_value!($iter, usize) - 1 }; ($iter:expr, $t:ty) => { $iter.next().unwrap().parse::<$t>().expect("Parse error") }; } // ---------- end input macro ---------- // ---------- begin chmin, chmax ---------- pub trait ChangeMinMax { fn chmin(&mut self, x: Self) -> bool; fn chmax(&mut self, x: Self) -> bool; } impl<T: PartialOrd> ChangeMinMax for T { fn chmin(&mut self, x: Self) -> bool { *self > x && { *self = x; true } } fn chmax(&mut self, x: Self) -> bool { *self < x && { *self = x; true } } } // ---------- end chmin, chmax ----------