結果

問題 No.1245 ANDORゲーム(calc)
ユーザー tentententen
提出日時 2023-01-11 15:13:55
言語 Java21
(openjdk 21)
結果
AC  
実行時間 531 ms / 2,000 ms
コード長 3,088 bytes
コンパイル時間 2,490 ms
コンパイル使用メモリ 94,020 KB
実行使用メモリ 66,788 KB
最終ジャッジ日時 2023-08-23 21:47:25
合計ジャッジ時間 15,666 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
49,712 KB
testcase_01 AC 44 ms
49,404 KB
testcase_02 AC 44 ms
50,024 KB
testcase_03 AC 44 ms
49,488 KB
testcase_04 AC 44 ms
49,612 KB
testcase_05 AC 44 ms
49,336 KB
testcase_06 AC 43 ms
49,580 KB
testcase_07 AC 106 ms
53,428 KB
testcase_08 AC 68 ms
50,984 KB
testcase_09 AC 109 ms
52,884 KB
testcase_10 AC 109 ms
53,536 KB
testcase_11 AC 513 ms
65,188 KB
testcase_12 AC 506 ms
64,588 KB
testcase_13 AC 480 ms
64,332 KB
testcase_14 AC 516 ms
65,000 KB
testcase_15 AC 473 ms
65,204 KB
testcase_16 AC 482 ms
65,284 KB
testcase_17 AC 434 ms
65,404 KB
testcase_18 AC 474 ms
65,272 KB
testcase_19 AC 472 ms
64,916 KB
testcase_20 AC 500 ms
64,036 KB
testcase_21 AC 475 ms
66,788 KB
testcase_22 AC 500 ms
65,204 KB
testcase_23 AC 476 ms
65,080 KB
testcase_24 AC 531 ms
65,336 KB
testcase_25 AC 374 ms
59,936 KB
testcase_26 AC 406 ms
59,820 KB
testcase_27 AC 434 ms
65,184 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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[] values = new int[n];
        for (int i = 0; i < n; i++) {
            values[i] = sc.nextInt();
        }
        char[] opps = sc.next().toCharArray();
        long[] ons = new long[31];
        long[] ofs = new long[31];
        for (int i = 0; i < 31; i++) {
            boolean tValue = true;
            boolean fValue = false;
            for (int j = 0; j < n; j++) {
                if (opps[j] == '0') {
                    if (tValue && !((values[j] & (1 << i)) > 0)) {
                        tValue = false;
                        ons[i] += (1 << i);
                    }
                    if (fValue && !((values[j] & (1 << i)) > 0)) {
                        fValue = false;
                        ofs[i] += (1 << i);
                    }
                } else {
                    if (!tValue && ((values[j] & (1 << i)) > 0)) {
                        tValue = true;
                        ons[i] += (1 << i);
                    }
                    if (!fValue && ((values[j] & (1 << i)) > 0)) {
                        fValue = true;
                        ofs[i] += (1 << i);
                    }
                }
            }
        }
        StringBuilder sb = new StringBuilder();
        while (q-- > 0) {
            int x = sc.nextInt();
            long ans = 0;
            for (int i = 0; i < 31; i++) {
                if ((x & (1 << i)) == 0) {
                    ans += ofs[i];
                } else {
                    ans += ons[i];
                }
            }
            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();
    }
    
}
0