結果

問題 No.1142 XOR と XOR
ユーザー tenten
提出日時 2021-08-06 08:58:22
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 1,818 bytes
コンパイル時間 2,115 ms
コンパイル使用メモリ 78,016 KB
実行使用メモリ 62,052 KB
最終ジャッジ日時 2024-09-16 21:36:20
合計ジャッジ時間 10,308 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 3 WA * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int m = sc.nextInt();
        int k = sc.nextInt();
        int[] aArr = new int[n];
        for (int i = 0; i < n; i++) {
            aArr[i] = sc.nextInt();
        }
        long[] aCount = get(aArr);
        int[] bArr = new int[m];
        for (int i = 0; i < m; i++) {
            bArr[i] = sc.nextInt();
        }
        long[] bCount = get(bArr);
        long ans = 0;
        for (int i = 0; i < 1024; i++) {
            ans += aCount[i] * bCount[i ^ k];
        }
        System.out.println(ans);
    }
    
    static long[] get(int[] arr) {
        long[] counts = new long[1024];
        counts[0]++;
        int base = 0;
        for (int x : arr) {
            base ^= x;
            counts[base] += 1;
        }
        long[] ans = new long[1024];
        for (int i = 0; i < 1024; i++) {
            for (int j = i + 1; j < 1024; j++) {
                ans[i ^ j] += counts[i] * counts[j];
            }
        }
        for (long x : counts) {
            ans[0] += x * (x - 1) / 2;
        }
        return ans;
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public String next() throws Exception {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0