結果

問題 No.1245 ANDORゲーム(calc)
ユーザー tentententen
提出日時 2020-10-05 09:08:34
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,226 ms / 2,000 ms
コード長 1,473 bytes
コンパイル時間 3,474 ms
コンパイル使用メモリ 74,380 KB
実行使用メモリ 75,724 KB
最終ジャッジ日時 2023-09-27 01:44:54
合計ジャッジ時間 28,501 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
55,924 KB
testcase_01 AC 125 ms
56,280 KB
testcase_02 AC 125 ms
55,636 KB
testcase_03 AC 124 ms
56,180 KB
testcase_04 AC 125 ms
55,892 KB
testcase_05 AC 125 ms
55,636 KB
testcase_06 AC 124 ms
55,648 KB
testcase_07 AC 246 ms
60,016 KB
testcase_08 AC 210 ms
58,996 KB
testcase_09 AC 235 ms
59,140 KB
testcase_10 AC 246 ms
59,256 KB
testcase_11 AC 1,226 ms
75,724 KB
testcase_12 AC 1,224 ms
69,588 KB
testcase_13 AC 1,198 ms
69,184 KB
testcase_14 AC 1,214 ms
69,408 KB
testcase_15 AC 1,170 ms
69,300 KB
testcase_16 AC 1,177 ms
68,396 KB
testcase_17 AC 1,206 ms
70,196 KB
testcase_18 AC 1,201 ms
69,172 KB
testcase_19 AC 1,162 ms
69,112 KB
testcase_20 AC 1,164 ms
69,436 KB
testcase_21 AC 1,148 ms
69,404 KB
testcase_22 AC 1,149 ms
70,512 KB
testcase_23 AC 1,130 ms
68,640 KB
testcase_24 AC 1,174 ms
69,252 KB
testcase_25 AC 976 ms
64,764 KB
testcase_26 AC 1,067 ms
67,476 KB
testcase_27 AC 1,208 ms
62,848 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        long[][] dp = new long[31][2];
        int[][] values = new int[31][2];
        for (int i = 0; i < 31; i++) {
            values[i][1] = 1;
        }
        int[] vArr = new int[n];
        for (int i = 0; i < n; i++) {
            vArr[i] = sc.nextInt();
        }
        char[] arr = sc.next().toCharArray();
        for (int i = 0; i < n; i++) {
            int a = vArr[i];
            for (int j = 0; j < 31; j++) {
                int bit = a % 2;
                a /= 2;
                for (int k = 0; k < 2; k++) {
                    if (bit == 1 && values[j][k] == 0 && arr[i] == '1') {
                        values[j][k] = 1;
                        dp[j][k] += (1 << j);
                    } else if (bit == 0 && values[j][k] == 1 && arr[i] == '0') {
                        values[j][k] = 0;
                        dp[j][k] += (1 << j);
                    }
                }
            }
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < q; i++) {
            int t = sc.nextInt();
            long ans = 0;
            for (int j = 0; j < 31; j++) {
                ans += dp[j][t % 2];
                t /= 2;
            }
            sb.append(ans).append("\n");
        }
        System.out.print(sb);
    }
}
0