結果
問題 |
No.1245 ANDORゲーム(calc)
|
ユーザー |
![]() |
提出日時 | 2024-03-12 19:58:42 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 546 ms / 2,000 ms |
コード長 | 2,261 bytes |
コンパイル時間 | 2,678 ms |
コンパイル使用メモリ | 82,408 KB |
実行使用メモリ | 67,388 KB |
最終ジャッジ日時 | 2024-09-29 22:25:08 |
合計ジャッジ時間 | 14,731 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 25 |
ソースコード
import java.io.*; import java.util.*; import java.util.function.*; import java.util.stream.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int q = sc.nextInt(); int[] values = new int[n]; for (int i = 0; i < n; i++) { values[i] = sc.nextInt(); } char[] bits = sc.next().toCharArray(); long[][] scores = new long[30][2]; for (int i = 0; i < 30; i++) { for (int j = 0; j < 2; j++) { int x = j; for (int k = 0; k < n; k++) { if (x == 0 && (values[k] & (1 << i)) > 0 && bits[k] == '1') { x = 1; scores[i][j] += (1 << i); } else if (x == 1 && (values[k] & (1 << i)) == 0 && bits[k] == '0') { x = 0; scores[i][j] += (1 << i); } } } } String result = IntStream.range(0, q).mapToObj(s -> { int x = sc.nextInt(); long ans = 0; for (int i = 0; i < 30; i++) { ans += scores[i][(x & (1 << i)) == 0 ? 0 : 1]; } return String.valueOf(ans); }).collect(Collectors.joining("\n")); System.out.println(result); } } class Scanner { BufferedReader br; StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() { try { br = new BufferedReader(new InputStreamReader(System.in)); } catch (Exception e) { } } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } public String next() { try { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } } catch (Exception e) { e.printStackTrace(); } finally { return st.nextToken(); } } }