結果
問題 |
No.1245 ANDORゲーム(calc)
|
ユーザー |
|
提出日時 | 2023-01-26 01:12:56 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 549 ms / 2,000 ms |
コード長 | 1,874 bytes |
コンパイル時間 | 14,482 ms |
コンパイル使用メモリ | 397,028 KB |
実行使用メモリ | 235,136 KB |
最終ジャッジ日時 | 2024-06-27 01:48:52 |
合計ジャッジ時間 | 26,284 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 25 |
コンパイルメッセージ
warning: unnecessary parentheses around index expression --> src/main.rs:42:63 | 42 | let result = (0..32).map(|i| (1usize << i) * dp[n][i][((t >> i) & 1)].1).sum::<usize>(); | ^ ^ | = note: `#[warn(unused_parens)]` on by default help: remove these parentheses | 42 - let result = (0..32).map(|i| (1usize << i) * dp[n][i][((t >> i) & 1)].1).sum::<usize>(); 42 + let result = (0..32).map(|i| (1usize << i) * dp[n][i][(t >> i) & 1].1).sum::<usize>(); | warning: unused variable: `q` --> src/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
ソースコード
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); } }