結果
| 問題 |
No.1296 OR or NOR
|
| コンテスト | |
| ユーザー |
noshi91
|
| 提出日時 | 2020-11-21 05:14:20 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,410 bytes |
| コンパイル時間 | 13,907 ms |
| コンパイル使用メモリ | 377,952 KB |
| 実行使用メモリ | 12,672 KB |
| 最終ジャッジ日時 | 2024-07-23 15:23:41 |
| 合計ジャッジ時間 | 19,992 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 30 WA * 3 |
ソースコード
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) -> T
where
T: 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();
}
noshi91