結果
問題 | No.1296 OR or NOR |
ユーザー |
![]() |
提出日時 | 2020-11-20 22:31:10 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 186 ms / 3,000 ms |
コード長 | 2,407 bytes |
コンパイル時間 | 17,832 ms |
コンパイル使用メモリ | 378,292 KB |
実行使用メモリ | 12,652 KB |
最終ジャッジ日時 | 2024-07-23 13:23:57 |
合計ジャッジ時間 | 19,857 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 33 |
ソースコード
use std::io::{self, Read as _, Write as _};struct Scanner<'a>(std::str::SplitWhitespace<'a>);impl<'a> Scanner<'a> {fn new(s: &'a str) -> Self {Self(s.split_whitespace())}fn next<T>(&mut self) -> TwhereT: std::str::FromStr,T::Err: std::fmt::Debug,{let s = self.0.next().expect("found EOF");match s.parse() {Ok(v) => v,Err(msg) => {println!("parse error. T = {}, s = \"{}\": {:?}",std::any::type_name::<T>(),s,msg);panic!()}}}}fn main() {let mut stdin = String::new();std::io::stdin().read_to_string(&mut stdin).unwrap();let mut sc = Scanner::new(&stdin);let stdout = io::stdout();let mut stdout = io::BufWriter::new(stdout.lock());let n: usize = sc.next();let a = (0..n).map(|_| sc.next()).collect::<Vec<u64>>().into_boxed_slice();let q: usize = sc.next();let b = (0..q).map(|_| sc.next()).collect::<Vec<u64>>().into_boxed_slice();let mut rem: u64 = !(!0 << 60);let (a, has_front) = {let mut c = vec![];let mut has_front = false;for a in a.into_vec().into_iter().rev() {if rem & a != 0 {c.push(a & rem);rem &= !a;has_front = false;} else {has_front = true;}}(c.into_boxed_slice(), has_front)};dbg!(&a);for mut b in b.into_vec() {let mut count: usize = 0;let mut valid: bool = true;for &c in a.iter() {if b & c == 0 {count += 1;b = !b;} else if !b & c == 0 {} else {valid = false;break;}}if b & rem == 0 {} else if !b & rem == 0 {if has_front {count += 1;} else {valid = false;}} else {valid = false;}if !valid {writeln!(stdout, "-1").unwrap();} else {writeln!(stdout, "{}", count).unwrap();}}stdout.flush().unwrap();}