結果
| 問題 |
No.1245 ANDORゲーム(calc)
|
| コンテスト | |
| ユーザー |
fukafukatani
|
| 提出日時 | 2020-10-03 17:25:53 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
AC
|
| 実行時間 | 179 ms / 2,000 ms |
| コード長 | 1,730 bytes |
| コンパイル時間 | 10,826 ms |
| コンパイル使用メモリ | 401,152 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-18 04:40:37 |
| 合計ジャッジ時間 | 15,883 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 25 |
コンパイルメッセージ
warning: unused variable: `q` --> src/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
ソースコード
#![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()
}
fukafukatani