結果
問題 | No.1245 ANDORゲーム(calc) |
ユーザー | tenten |
提出日時 | 2023-03-22 14:56:41 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 589 ms / 2,000 ms |
コード長 | 2,766 bytes |
コンパイル時間 | 3,124 ms |
コンパイル使用メモリ | 91,140 KB |
実行使用メモリ | 70,888 KB |
最終ジャッジ日時 | 2023-10-18 18:59:45 |
合計ジャッジ時間 | 15,616 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 54 ms
53,380 KB |
testcase_01 | AC | 55 ms
53,436 KB |
testcase_02 | AC | 54 ms
53,428 KB |
testcase_03 | AC | 54 ms
52,332 KB |
testcase_04 | AC | 55 ms
53,436 KB |
testcase_05 | AC | 54 ms
52,320 KB |
testcase_06 | AC | 53 ms
53,436 KB |
testcase_07 | AC | 126 ms
55,956 KB |
testcase_08 | AC | 81 ms
54,832 KB |
testcase_09 | AC | 112 ms
55,376 KB |
testcase_10 | AC | 128 ms
57,348 KB |
testcase_11 | AC | 589 ms
70,480 KB |
testcase_12 | AC | 562 ms
70,648 KB |
testcase_13 | AC | 588 ms
70,632 KB |
testcase_14 | AC | 562 ms
67,348 KB |
testcase_15 | AC | 542 ms
68,044 KB |
testcase_16 | AC | 573 ms
70,888 KB |
testcase_17 | AC | 563 ms
68,348 KB |
testcase_18 | AC | 549 ms
70,684 KB |
testcase_19 | AC | 551 ms
70,328 KB |
testcase_20 | AC | 543 ms
68,308 KB |
testcase_21 | AC | 546 ms
70,752 KB |
testcase_22 | AC | 550 ms
68,424 KB |
testcase_23 | AC | 574 ms
70,308 KB |
testcase_24 | AC | 537 ms
67,356 KB |
testcase_25 | AC | 392 ms
60,640 KB |
testcase_26 | AC | 424 ms
62,968 KB |
testcase_27 | AC | 532 ms
67,832 KB |
ソースコード
import java.io.*; import java.util.*; 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[] inputs = new int[n]; for (int i = 0; i < n; i++) { inputs[i] = sc.nextInt(); } char[] andor = sc.next().toCharArray(); long[][] values = new long[2][31]; for (int i = 0; i <= 30; i++) { boolean[] current = new boolean[]{false, true}; for (int j = 0; j < n; j++) { for (int k = 0; k < 2; k++) { if (andor[j] == '0') { if (inputs[j] % 2 == 0 && current[k]) { current[k] = false; values[k][i] += (1 << i); } } else { if (inputs[j] % 2 == 1 && !current[k]) { current[k] = true; values[k][i] += (1 << i); } } } inputs[j] >>= 1; } } StringBuilder sb = new StringBuilder(); while (q-- > 0) { int x = sc.nextInt(); long ans = 0; for (int i = 0; i <= 30; i++) { ans += values[x % 2][i]; x >>= 1; } sb.append(ans).append("\n"); } System.out.print(sb); } } class Utilities { static String arrayToLineString(Object[] arr) { return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n")); } static String arrayToLineString(int[] arr) { return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new)); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public int[] nextIntArray() throws Exception { return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }