結果
問題 | No.1296 OR or NOR |
ユーザー | koba-e964 |
提出日時 | 2020-11-20 23:07:26 |
言語 | Rust (1.77.0 + proconio) |
結果 |
MLE
|
実行時間 | - |
コード長 | 4,051 bytes |
コンパイル時間 | 16,589 ms |
コンパイル使用メモリ | 387,356 KB |
実行使用メモリ | 721,788 KB |
最終ジャッジ日時 | 2024-07-23 13:42:08 |
合計ジャッジ時間 | 21,056 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
13,884 KB |
testcase_01 | AC | 2 ms
6,816 KB |
testcase_02 | AC | 101 ms
6,944 KB |
testcase_03 | AC | 99 ms
6,944 KB |
testcase_04 | MLE | - |
testcase_05 | -- | - |
testcase_06 | -- | - |
testcase_07 | -- | - |
testcase_08 | -- | - |
testcase_09 | -- | - |
testcase_10 | -- | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
ソースコード
#[allow(unused_imports)] use std::cmp::*; #[allow(unused_imports)] use std::collections::*; use std::io::{Write, BufWriter}; // https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 macro_rules! input { ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes.by_ref().map(|r|r.unwrap() as char) .skip_while(|c|c.is_whitespace()) .take_while(|c|!c.is_whitespace()) .collect() }; input_inner!{next, $($r)*} }; } macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} }; } macro_rules! read_value { ($next:expr, [graph1; $len:expr]) => {{ let mut g = vec![vec![]; $len]; let ab = read_value!($next, [(usize1, usize1)]); for (a, b) in ab { g[a].push(b); g[b].push(a); } g }}; ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, usize1) => (read_value!($next, usize) - 1); ($next:expr, [ $t:tt ]) => {{ let len = read_value!($next, usize); read_value!($next, [$t; len]) }}; ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error")); } #[allow(unused)] macro_rules! debug { ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap()); } #[allow(unused)] macro_rules! debugln { ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap()); } const INF: i64 = 1 << 50; fn solve() { let out = std::io::stdout(); let mut out = BufWriter::new(out.lock()); macro_rules! puts { ($($format:tt)*) => (let _ = write!(out,$($format)*);); } #[allow(unused)] macro_rules! putvec { ($v:expr) => { for i in 0..$v.len() { puts!("{}{}", $v[i], if i + 1 == $v.len() {"\n"} else {" "}); } } } input! { n: usize, a: [i64; n], q: usize, b: [i64; q], } let whole = (1i64 << 60) - 1; let mut now = HashMap::new(); now.insert((0, 0, false), 0); for i in (0..n).rev() { let mut nxt = HashMap::new(); for ((off, on, not), v) in now { if v >= 62 { continue; } let fr = off | on; let rem = a[i] & !fr; let st = if not { (off | rem, on, true) } else { (off, on | rem, false) }; let r = nxt.entry(st).or_insert(INF); *r = min(*r, v); let st = if not { (off, on | rem, false) } else { (off | rem, on, true) }; let r = nxt.entry(st).or_insert(INF); *r = min(*r, v + 1); } now = nxt; } //eprintln!("now = {:?}", now); for b in b { let mut mi = INF; for (&(off, on, not), &v) in &now { assert_eq!(off & on, 0); if not { if off != (whole ^ b) { continue; } } else { if on != b { continue; } } mi = min(mi, v); } if mi < INF { puts!("{}\n", mi); } else { puts!("-1\n"); } } } fn main() { // In order to avoid potential stack overflow, spawn a new thread. let stack_size = 104_857_600; // 100 MB let thd = std::thread::Builder::new().stack_size(stack_size); thd.spawn(|| solve()).unwrap().join().unwrap(); }