結果

問題 No.1245 ANDORゲーム(calc)
ユーザー ks2mks2m
提出日時 2020-10-02 22:51:15
言語 Java21
(openjdk 21)
結果
AC  
実行時間 603 ms / 2,000 ms
コード長 1,480 bytes
コンパイル時間 1,970 ms
コンパイル使用メモリ 74,032 KB
実行使用メモリ 72,772 KB
最終ジャッジ日時 2023-09-24 22:23:42
合計ジャッジ時間 14,542 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
49,492 KB
testcase_01 AC 44 ms
49,528 KB
testcase_02 AC 44 ms
49,488 KB
testcase_03 AC 44 ms
49,304 KB
testcase_04 AC 44 ms
49,304 KB
testcase_05 AC 44 ms
49,288 KB
testcase_06 AC 45 ms
49,900 KB
testcase_07 AC 112 ms
52,436 KB
testcase_08 AC 69 ms
51,388 KB
testcase_09 AC 100 ms
52,472 KB
testcase_10 AC 110 ms
52,308 KB
testcase_11 AC 528 ms
67,400 KB
testcase_12 AC 537 ms
67,968 KB
testcase_13 AC 602 ms
68,136 KB
testcase_14 AC 526 ms
66,800 KB
testcase_15 AC 519 ms
66,564 KB
testcase_16 AC 533 ms
72,772 KB
testcase_17 AC 502 ms
65,924 KB
testcase_18 AC 528 ms
67,344 KB
testcase_19 AC 536 ms
68,424 KB
testcase_20 AC 515 ms
66,608 KB
testcase_21 AC 564 ms
66,932 KB
testcase_22 AC 597 ms
69,280 KB
testcase_23 AC 542 ms
66,408 KB
testcase_24 AC 603 ms
66,772 KB
testcase_25 AC 516 ms
68,016 KB
testcase_26 AC 545 ms
68,416 KB
testcase_27 AC 601 ms
69,056 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int q = Integer.parseInt(sa[1]);

		sa = br.readLine().split(" ");
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(sa[i]);
		}

		char[] s = br.readLine().toCharArray();

		sa = br.readLine().split(" ");
		int[] t = new int[q];
		for (int i = 0; i < q; i++) {
			t[i] = Integer.parseInt(sa[i]);
		}
		br.close();

		long[] dp0 = new long[31];
		long[] dp1 = new long[31];
		int now0 = 0;
		int now1 = Integer.MAX_VALUE;
		for (int i = 0; i < n; i++) {
			int next0 = 0;
			int next1 = 0;
			if (s[i] == '0') {
				next0 = now0 & a[i];
				next1 = now1 & a[i];
			} else {
				next0 = now0 | a[i];
				next1 = now1 | a[i];
			}
			for (int j = 0; j < 31; j++) {
				int c = 1 << j;
				if ((now0 & c) != (next0 & c)) {
					dp0[j] += c;
				}
				if ((now1 & c) != (next1 & c)) {
					dp1[j] += c;
				}
			}
			now0 = next0;
			now1 = next1;
		}

		PrintWriter pw = new PrintWriter(System.out);
		for (int i = 0; i < q; i++) {
			long ans = 0;
			for (int j = 0; j < 31; j++) {
				if ((t[i] >> j & 1) == 0) {
					ans += dp0[j];
				} else {
					ans += dp1[j];
				}
			}
			pw.println(ans);
		}
		pw.flush();
	}
}
0