結果

問題 No.1142 XOR と XOR
ユーザー 37zigen37zigen
提出日時 2020-08-01 00:33:19
言語 Java21
(openjdk 21)
結果
AC  
実行時間 190 ms / 2,000 ms
コード長 3,488 bytes
コンパイル時間 2,016 ms
コンパイル使用メモリ 78,048 KB
実行使用メモリ 57,096 KB
最終ジャッジ日時 2024-04-25 16:33:55
合計ジャッジ時間 7,701 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 104 ms
51,640 KB
testcase_01 AC 107 ms
51,620 KB
testcase_02 AC 110 ms
51,692 KB
testcase_03 AC 185 ms
57,096 KB
testcase_04 AC 184 ms
54,908 KB
testcase_05 AC 188 ms
55,844 KB
testcase_06 AC 189 ms
55,500 KB
testcase_07 AC 189 ms
54,888 KB
testcase_08 AC 185 ms
54,904 KB
testcase_09 AC 189 ms
54,764 KB
testcase_10 AC 190 ms
55,152 KB
testcase_11 AC 113 ms
51,784 KB
testcase_12 AC 101 ms
51,840 KB
testcase_13 AC 108 ms
51,732 KB
testcase_14 AC 175 ms
52,576 KB
testcase_15 AC 182 ms
52,756 KB
testcase_16 AC 141 ms
51,700 KB
testcase_17 AC 171 ms
55,456 KB
testcase_18 AC 139 ms
52,092 KB
testcase_19 AC 174 ms
55,456 KB
testcase_20 AC 177 ms
52,852 KB
testcase_21 AC 165 ms
52,260 KB
testcase_22 AC 140 ms
51,872 KB
testcase_23 AC 180 ms
55,548 KB
testcase_24 AC 174 ms
55,288 KB
testcase_25 AC 178 ms
52,864 KB
testcase_26 AC 186 ms
55,416 KB
testcase_27 AC 162 ms
54,596 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {
		new Main().run();
	}
	
	final long MOD=(long)1e9+7;

	void run() {
		FastScanner sc=new FastScanner();
		int N=sc.nextInt();
		int M=sc.nextInt();
		int K=sc.nextInt();
		int[] A=new int[N];
		int[] suma=new int[N+1];
		int[] B=new int[M];
		int[] sumb=new int[M+1];
		long[] cnta=new long[1<<10];
		long[] cntb=new long[1<<10];
		for (int i=0;i<N;++i) {
			A[i]=sc.nextInt();
			suma[i+1]=suma[i]^A[i];
		}
		for (int a:suma) cnta[a]++;
		for (int i=0;i<M;++i) {
			B[i]=sc.nextInt();
			sumb[i+1]=sumb[i]^B[i];
		}
		for (int b:sumb) cntb[b]++;
		long[][] cnt=new long[2][1<<10];
		for (int i=0;i<1<<10;++i) {
			for (int j=i+1;j<1<<10;++j) {
				int v=i^j;
				long add=cnta[i]*cnta[j]%MOD;
				cnt[0][v]=(cnt[0][v]+add)%MOD;
			}
			cnt[0][0]=(cnt[0][0]+cnta[i]*(cnta[i]-1)/2%MOD)%MOD;
		}
		
		for (int i=0;i<1<<10;++i) {
			for (int j=i+1;j<1<<10;++j) {
				int v=i^j;
				long add=cntb[i]*cntb[j]%MOD;
				cnt[1][v]=(cnt[1][v]+add)%MOD;
			}
			cnt[1][0]=(cnt[1][0]+cntb[i]*(cntb[i]-1)/2%MOD)%MOD;
		}
		
		
		long ans=0;
		for (int i=0;i<1<<10;++i) {
			for (int j=0;j<1<<10;++j) {
				if ((i^j)!=K) continue;
				ans+=cnt[0][i]*cnt[1][j]%MOD;
				ans%=MOD;
			}
		}
		System.out.println(ans);
	}
	
	void tr(Object...objects) {System.out.println(Arrays.deepToString(objects));}
	
	
	class FastScanner {
	    private final InputStream in = System.in;
	    private final byte[] buffer = new byte[1024];
	    private int ptr = 0;
	    private int buflen = 0;
	    private boolean hasNextByte() {
	        if (ptr < buflen) {
	            return true;
	        }else{
	            ptr = 0;
	            try {
	                buflen = in.read(buffer);
	            } catch (IOException e) {
	                e.printStackTrace();
	            }
	            if (buflen <= 0) {
	                return false;
	            }
	        }
	        return true;
	    }
	    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
	    private boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
	    private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
	    public boolean hasNext() { skipUnprintable(); return hasNextByte();}
	    public String next() {
	        if (!hasNext()) throw new NoSuchElementException();
	        StringBuilder sb = new StringBuilder();
	        int b = readByte();
	        while(isPrintableChar(b)) {
	            sb.appendCodePoint(b);
	            b = readByte();
	        }
	        return sb.toString();
	    }
	    public long nextLong() {
	        if (!hasNext()) throw new NoSuchElementException();
	        long n = 0;
	        boolean minus = false;
	        int b = readByte();
	        if (b == '-') {
	            minus = true;
	            b = readByte();
	        }
	        if (b < '0' || '9' < b) {
	            throw new NumberFormatException();
	        }
	        while(true){
	            if ('0' <= b && b <= '9') {
	                n *= 10;
	                n += b - '0';
	            }else if(b == -1 || !isPrintableChar(b)){
	                return minus ? -n : n;
	            }else{
	                throw new NumberFormatException();
	            }
	            b = readByte();
	        }
	    }
	    public int nextInt() {
	    	return (int)nextLong();
	    }
	}
}

0