結果
| 問題 |
No.1142 XOR と XOR
|
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2023-04-11 11:26:17 |
| 言語 | Java (openjdk 23) |
| 結果 |
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 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 25 |
ソースコード
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();
}
}
tenten