結果

問題 No.1296 OR or NOR
ユーザー noshi91noshi91
提出日時 2020-11-21 05:14:20
言語 Rust
(1.72.1)
結果
WA  
実行時間 -
コード長 2,410 bytes
コンパイル時間 1,873 ms
コンパイル使用メモリ 157,512 KB
実行使用メモリ 13,268 KB
最終ジャッジ日時 2023-09-30 21:36:13
合計ジャッジ時間 7,937 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 78 ms
13,164 KB
testcase_05 WA -
testcase_06 AC 62 ms
13,240 KB
testcase_07 AC 60 ms
13,260 KB
testcase_08 AC 61 ms
13,172 KB
testcase_09 AC 61 ms
13,244 KB
testcase_10 AC 62 ms
13,252 KB
testcase_11 AC 48 ms
9,104 KB
testcase_12 AC 49 ms
13,248 KB
testcase_13 AC 54 ms
13,248 KB
testcase_14 AC 133 ms
13,264 KB
testcase_15 AC 91 ms
13,200 KB
testcase_16 AC 61 ms
13,260 KB
testcase_17 AC 60 ms
13,260 KB
testcase_18 AC 59 ms
13,212 KB
testcase_19 AC 60 ms
13,268 KB
testcase_20 AC 36 ms
7,576 KB
testcase_21 AC 37 ms
7,520 KB
testcase_22 AC 34 ms
7,592 KB
testcase_23 AC 35 ms
7,588 KB
testcase_24 AC 35 ms
7,532 KB
testcase_25 AC 36 ms
7,580 KB
testcase_26 AC 35 ms
7,588 KB
testcase_27 AC 36 ms
7,584 KB
testcase_28 AC 35 ms
7,520 KB
testcase_29 AC 35 ms
7,536 KB
testcase_30 AC 125 ms
13,260 KB
testcase_31 AC 124 ms
13,260 KB
testcase_32 AC 124 ms
13,244 KB
testcase_33 AC 63 ms
13,252 KB
testcase_34 AC 63 ms
13,236 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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();
}
0