結果
問題 | No.1245 ANDORゲーム(calc) |
ユーザー | tenten |
提出日時 | 2023-11-17 08:47:28 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 876 ms / 2,000 ms |
コード長 | 2,624 bytes |
コンパイル時間 | 2,718 ms |
コンパイル使用メモリ | 89,820 KB |
実行使用メモリ | 75,328 KB |
最終ジャッジ日時 | 2023-11-17 08:47:48 |
合計ジャッジ時間 | 18,640 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 52 ms
54,036 KB |
testcase_01 | AC | 52 ms
54,004 KB |
testcase_02 | AC | 53 ms
53,996 KB |
testcase_03 | AC | 52 ms
52,020 KB |
testcase_04 | AC | 53 ms
54,016 KB |
testcase_05 | AC | 53 ms
53,984 KB |
testcase_06 | AC | 52 ms
54,000 KB |
testcase_07 | AC | 125 ms
56,436 KB |
testcase_08 | AC | 83 ms
55,272 KB |
testcase_09 | AC | 131 ms
56,532 KB |
testcase_10 | AC | 126 ms
57,860 KB |
testcase_11 | AC | 590 ms
70,312 KB |
testcase_12 | AC | 813 ms
75,288 KB |
testcase_13 | AC | 602 ms
69,556 KB |
testcase_14 | AC | 876 ms
75,328 KB |
testcase_15 | AC | 567 ms
70,016 KB |
testcase_16 | AC | 623 ms
69,720 KB |
testcase_17 | AC | 592 ms
69,340 KB |
testcase_18 | AC | 596 ms
69,188 KB |
testcase_19 | AC | 579 ms
67,944 KB |
testcase_20 | AC | 572 ms
69,364 KB |
testcase_21 | AC | 558 ms
70,040 KB |
testcase_22 | AC | 615 ms
69,836 KB |
testcase_23 | AC | 588 ms
68,004 KB |
testcase_24 | AC | 824 ms
74,768 KB |
testcase_25 | AC | 538 ms
70,744 KB |
testcase_26 | AC | 479 ms
68,444 KB |
testcase_27 | AC | 550 ms
69,564 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(); boolean[][] state = new boolean[n][30]; for (int i = 0; i < n; i++) { int x = sc.nextInt(); for (int j = 0; j < 30; j++) { state[i][j] = (x % 2 == 1); x >>= 1; } } char[] isAnd = sc.next().toCharArray(); long[][] count = new long[30][2]; 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 ((isAnd[j] == '0' && current[k] && !state[j][i]) || (isAnd[j] == '1' && !current[k] && state[j][i])) { count[i][k]++; current[k] ^= true; } } } } StringBuilder sb = new StringBuilder(); while (q-- > 0) { int x = sc.nextInt(); long ans = 0; for (int i = 0; i < 30; i++) { ans += (count[i][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(); } }