結果

問題 No.1142 XOR と XOR
ユーザー tentententen
提出日時 2023-04-11 11:26:17
言語 Java21
(openjdk 21)
結果
AC  
実行時間 405 ms / 2,000 ms
コード長 3,353 bytes
コンパイル時間 2,686 ms
コンパイル使用メモリ 83,552 KB
実行使用メモリ 49,272 KB
最終ジャッジ日時 2024-10-07 03:34:17
合計ジャッジ時間 12,296 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 96 ms
38,644 KB
testcase_01 AC 94 ms
38,784 KB
testcase_02 AC 95 ms
38,604 KB
testcase_03 AC 405 ms
49,044 KB
testcase_04 AC 329 ms
45,680 KB
testcase_05 AC 357 ms
46,860 KB
testcase_06 AC 334 ms
47,480 KB
testcase_07 AC 370 ms
47,292 KB
testcase_08 AC 359 ms
46,784 KB
testcase_09 AC 329 ms
47,356 KB
testcase_10 AC 358 ms
49,068 KB
testcase_11 AC 95 ms
38,372 KB
testcase_12 AC 105 ms
40,248 KB
testcase_13 AC 87 ms
38,700 KB
testcase_14 AC 299 ms
45,460 KB
testcase_15 AC 328 ms
46,244 KB
testcase_16 AC 186 ms
42,200 KB
testcase_17 AC 327 ms
46,564 KB
testcase_18 AC 217 ms
43,188 KB
testcase_19 AC 382 ms
47,492 KB
testcase_20 AC 305 ms
45,192 KB
testcase_21 AC 228 ms
44,536 KB
testcase_22 AC 237 ms
44,224 KB
testcase_23 AC 330 ms
49,272 KB
testcase_24 AC 319 ms
46,528 KB
testcase_25 AC 310 ms
46,312 KB
testcase_26 AC 350 ms
47,084 KB
testcase_27 AC 348 ms
46,016 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.util.stream.*;

public class Main {
    static final int MOD = 1000000007;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int m = sc.nextInt();
        int k = sc.nextInt();
        long[] countsA = new long[1024];
        int current = 0;
        countsA[0]++;
        for (int i = 0; i < n; i++) {
            current ^= sc.nextInt();
            countsA[current]++;
        }
        long[] ansA = new long[1024];
        for (int i = 0; i < 1024; i++) {
            for (int j = i; j < 1024; j++) {
                if (i == j) {
                    if (countsA[i] % 2 == 0) {
                        ansA[0] += countsA[i] / 2 * (countsA[i] - 1) % MOD;
                    } else {
                        ansA[0] += (countsA[i] - 1) / 2 * countsA[i] % MOD;
                    }
                    ansA[0] %= MOD;
                } else {
                    ansA[i ^ j] += countsA[i] * countsA[j] % MOD;
                    ansA[i ^ j] %= MOD;
                }
            }
        }
        long[] countsB = new long[1024];
        current = 0;
        countsB[0]++;
        for (int i = 0; i < m; i++) {
            current ^= sc.nextInt();
            countsB[current]++;
        }
        long[] ansB = new long[1024];
        for (int i = 0; i < 1024; i++) {
            for (int j = i; j < 1024; j++) {
                if (i == j) {
                    if (countsB[i] % 2 == 0) {
                        ansB[0] += countsB[i] / 2 * (countsB[i] - 1) % MOD;
                    } else {
                        ansB[0] += (countsB[i] - 1) / 2 * countsB[i] % MOD;
                    }
                    ansB[0] %= MOD;
                } else {
                    ansB[i ^ j] += countsB[i] * countsB[j] % MOD;
                    ansB[i ^ j] %= MOD;
                }
            }
        }
        long ans = 0;
        for (int i = 0; i < 1024; i++) {
            ans += ansA[i] * ansB[i ^ k] % MOD;
            ans %= MOD;
        }
        System.out.println(ans);
    }
}
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