結果

問題 No.1245 ANDORゲーム(calc)
ユーザー fukafukatanifukafukatani
提出日時 2020-10-03 17:25:53
言語 Rust
(1.77.0)
結果
AC  
実行時間 209 ms / 2,000 ms
コード長 1,730 bytes
コンパイル時間 1,826 ms
コンパイル使用メモリ 151,112 KB
実行使用メモリ 5,168 KB
最終ジャッジ日時 2023-09-25 05:29:25
合計ジャッジ時間 7,254 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 5 ms
4,380 KB
testcase_08 AC 3 ms
4,376 KB
testcase_09 AC 5 ms
4,376 KB
testcase_10 AC 6 ms
4,376 KB
testcase_11 AC 209 ms
5,164 KB
testcase_12 AC 209 ms
5,156 KB
testcase_13 AC 208 ms
5,096 KB
testcase_14 AC 205 ms
5,168 KB
testcase_15 AC 207 ms
5,160 KB
testcase_16 AC 208 ms
5,164 KB
testcase_17 AC 191 ms
5,152 KB
testcase_18 AC 185 ms
5,060 KB
testcase_19 AC 183 ms
5,084 KB
testcase_20 AC 192 ms
5,164 KB
testcase_21 AC 189 ms
5,084 KB
testcase_22 AC 183 ms
5,144 KB
testcase_23 AC 200 ms
5,156 KB
testcase_24 AC 198 ms
5,160 KB
testcase_25 AC 154 ms
4,980 KB
testcase_26 AC 156 ms
5,060 KB
testcase_27 AC 165 ms
5,064 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused variable: `q`
  --> Main.rs:20:13
   |
20 |     let (n, q) = (v[0], v[1]);
   |             ^ help: if this is intentional, prefix it with an underscore: `_q`
   |
   = note: `#[warn(unused_variables)]` on by default

warning: 1 warning emitted

ソースコード

diff #

#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;
use std::ops::Bound::*;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<usize>();
    let (n, q) = (v[0], v[1]);
    let a = read_vec::<i64>();
    let s = read::<String>().chars().collect::<Vec<_>>();
    let t = read_vec::<i64>();

    let mut scores = vec![vec![0i64; 32]; 2];
    for i in 0..2 {
        for bi in 0..32 {
            let mut cur = i;
            for qi in 0..n {
                let ch = s[qi];
                let anum = a[qi];
                let abit = (anum >> bi) & 1;
                if ch == '0' && cur == 1 && abit == 0 {
                    scores[i][bi] += 1 << bi;
                    cur = 0;
                } else if ch == '1' && cur == 0 && abit == 1 {
                    scores[i][bi] += 1 << bi;
                    cur = 1;
                }
            }
        }
    }

    for tnum in t {
        let mut ans = 0;
        for bi in 0..32 {
            let bit = (tnum >> bi) & 1;
            //debug!((tnum, bi, bit, scores[bit as usize][bi]));
            ans += scores[bit as usize][bi];
        }
        println!("{}", ans);
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
0