結果

問題 No.1142 XOR と XOR
ユーザー tenten
提出日時 2021-12-07 09:30:28
言語 Java
(openjdk 23)
結果
TLE  
実行時間 -
コード長 2,245 bytes
コンパイル時間 2,162 ms
コンパイル使用メモリ 77,744 KB
実行使用メモリ 63,328 KB
最終ジャッジ日時 2024-07-07 10:22:25
合計ジャッジ時間 39,279 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20 TLE * 5
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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();
        int[] countsA = new int[1024];
        int[] ansA = new int[1024];
        for (int i = 0; i < n; i++) {
            int[] next = new int[1024];
            int x = sc.nextInt();
            for (int j = 0; j < 1024; j++) {
                next[j ^ x] += countsA[j];
                next[j ^ x] %= MOD;
            }
            next[x]++;
            next[x] %= MOD;
            countsA = next;
            for (int j = 0; j < 1024; j++) {
                ansA[j] += countsA[j];
                ansA[j] %= MOD;
            }
        }
        int[] countsB = new int[1024];
        int[] ansB = new int[1024];
        for (int i = 0; i < m; i++) {
            int[] next = new int[1024];
            int x = sc.nextInt();
            for (int j = 0; j < 1024; j++) {
                next[j ^ x] += countsB[j];
                next[j ^ x] %= MOD;
            }
            next[x]++;
            next[x] %= MOD;
            countsB = next;
            for (int j = 0; j < 1024; j++) {
                ansB[j] += countsB[j];
                ansB[j] %= MOD;
            }
        }
        long ans = 0;
        for (int i = 0; i < 1024; i++) {
            ans += (long)ansA[i] * ansB[i ^ k];
            ans %= MOD;
        }
        System.out.println(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 double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public String next() throws Exception {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0