結果

問題 No.1245 ANDORゲーム(calc)
ユーザー CuriousFairy315CuriousFairy315
提出日時 2020-10-02 22:17:52
言語 Java19
(openjdk 21)
結果
AC  
実行時間 1,574 ms / 2,000 ms
コード長 1,080 bytes
コンパイル時間 2,310 ms
コンパイル使用メモリ 74,436 KB
実行使用メモリ 70,572 KB
最終ジャッジ日時 2023-09-24 21:12:44
合計ジャッジ時間 32,704 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
55,500 KB
testcase_01 AC 126 ms
55,852 KB
testcase_02 AC 128 ms
55,852 KB
testcase_03 AC 125 ms
55,368 KB
testcase_04 AC 124 ms
55,592 KB
testcase_05 AC 125 ms
55,552 KB
testcase_06 AC 123 ms
55,640 KB
testcase_07 AC 294 ms
59,792 KB
testcase_08 AC 233 ms
57,268 KB
testcase_09 AC 278 ms
59,408 KB
testcase_10 AC 306 ms
59,904 KB
testcase_11 AC 1,533 ms
69,840 KB
testcase_12 AC 1,551 ms
69,596 KB
testcase_13 AC 1,563 ms
69,816 KB
testcase_14 AC 1,507 ms
67,640 KB
testcase_15 AC 1,560 ms
70,572 KB
testcase_16 AC 1,570 ms
69,536 KB
testcase_17 AC 1,491 ms
69,152 KB
testcase_18 AC 1,489 ms
69,348 KB
testcase_19 AC 1,544 ms
69,400 KB
testcase_20 AC 1,551 ms
69,772 KB
testcase_21 AC 1,532 ms
69,528 KB
testcase_22 AC 1,509 ms
69,492 KB
testcase_23 AC 1,526 ms
69,388 KB
testcase_24 AC 1,535 ms
69,192 KB
testcase_25 AC 1,349 ms
68,632 KB
testcase_26 AC 1,331 ms
69,692 KB
testcase_27 AC 1,574 ms
69,308 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import static java.lang.System.*;

public class Main {

	public static void main(String[] args) {
		try (Scanner sc = new Scanner(in)) {
			int N = sc.nextInt(), Q = sc.nextInt();
			int[] A = new int[N];
			for (int i = 0;i < N;++ i) A[i] = sc.nextInt();
			char[] S = sc.next().toCharArray();
			long[] bit0 = new long[30], bit1 = new long[30];
			for (int i = 0;i < 30;++ i) {
				int b0 = 0, b1 = 1;
				for (int j = 0;j < N;++ j) {
					if (S[j] == '0') {
						if ((A[j] >> i & 1) == 0 && b0 == 1) bit0[i] += 1 << i;
						if ((A[j] >> i & 1) == 0 && b1 == 1) bit1[i] += 1 << i;
						b0 &= A[j] >> i & 1;
						b1 &= A[j] >> i & 1;
					} else {
						if ((A[j] >> i & 1) != 0 && b0 == 0) bit0[i] += 1 << i;
						if ((A[j] >> i & 1) != 0 && b1 == 0) bit1[i] += 1 << i;
						b0 |= A[j] >> i & 1;
						b1 |= A[j] >> i & 1;
					}
				}
			}
			while(Q --> 0) {
				int t = sc.nextInt();
				long ans = 0;
				for (int i = 0;i < 30;++ i) {
					if ((1 << i & t) == 0) ans += bit0[i];
					else ans += bit1[i];
				}
				out.println(ans);
			}
		}
	}

}
0