結果

問題 No.1245 ANDORゲーム(calc)
ユーザー phsplsphspls
提出日時 2023-01-26 01:12:56
言語 Rust
(1.77.0)
結果
AC  
実行時間 573 ms / 2,000 ms
コード長 1,874 bytes
コンパイル時間 3,697 ms
コンパイル使用メモリ 147,168 KB
実行使用メモリ 235,116 KB
最終ジャッジ日時 2023-09-09 08:41:27
合計ジャッジ時間 15,727 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 14 ms
8,432 KB
testcase_08 AC 4 ms
4,376 KB
testcase_09 AC 13 ms
7,912 KB
testcase_10 AC 12 ms
6,292 KB
testcase_11 AC 573 ms
235,116 KB
testcase_12 AC 499 ms
234,840 KB
testcase_13 AC 554 ms
234,064 KB
testcase_14 AC 497 ms
232,972 KB
testcase_15 AC 506 ms
234,832 KB
testcase_16 AC 486 ms
235,024 KB
testcase_17 AC 550 ms
233,164 KB
testcase_18 AC 487 ms
234,192 KB
testcase_19 AC 485 ms
232,836 KB
testcase_20 AC 551 ms
235,036 KB
testcase_21 AC 548 ms
234,972 KB
testcase_22 AC 492 ms
234,928 KB
testcase_23 AC 541 ms
232,928 KB
testcase_24 AC 543 ms
233,912 KB
testcase_25 AC 544 ms
234,332 KB
testcase_26 AC 541 ms
234,332 KB
testcase_27 AC 542 ms
234,792 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused variable: `q`
 --> Main.rs:7:9
  |
7 |     let q = nq[1];
  |         ^ help: if this is intentional, prefix it with an underscore: `_q`
  |
  = note: `#[warn(unused_variables)]` on by default

warning: 1 warning emitted

ソースコード

diff #

fn main() {
    let mut nq = String::new();
    std::io::stdin().read_line(&mut nq).ok();
    let nq: Vec<usize> = nq.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let n = nq[0];
    let q = nq[1];
    let mut a = String::new();
    std::io::stdin().read_line(&mut a).ok();
    let a: Vec<usize> = a.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    let s = s.trim().chars().map(|c| c as usize - '0' as usize).collect::<Vec<_>>();
    let mut t = String::new();
    std::io::stdin().read_line(&mut t).ok();
    let t: Vec<usize> = t.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();

    let mut dp = vec![vec![vec![(0usize, 0usize); 2]; 32]; n+1];
    for i in 0..32 {
        dp[0][i][1] = (1usize, 0usize);
    }
    for i in 0..n {
        for j in 0..32 {
            if s[i] == 0 {
                let (pval, pscore) = dp[i][j][0];
                let nval = pval & ((a[i] >> j) & 1);
                dp[i+1][j][0] = (nval, pscore + nval.max(pval) - nval.min(pval));
                let (pval, pscore) = dp[i][j][1];
                let nval = pval & ((a[i] >> j) & 1);
                dp[i+1][j][1] = (nval, pscore + nval.max(pval) - nval.min(pval));
            } else {
                let (pval, pscore) = dp[i][j][0];
                let nval = pval | ((a[i] >> j) & 1);
                dp[i+1][j][0] = (nval, pscore + nval.max(pval) - nval.min(pval));
                let (pval, pscore) = dp[i][j][1];
                let nval = pval | ((a[i] >> j) & 1);
                dp[i+1][j][1] = (nval, pscore + nval.max(pval) - nval.min(pval));
            }
        }
    }
    for &t in t.iter() {
        let result = (0..32).map(|i| (1usize << i) * dp[n][i][((t >> i) & 1)].1).sum::<usize>();
        println!("{}", result);
    }
}
0