結果

問題 No.1210 XOR Grid
ユーザー e869120
提出日時 2021-02-26 09:06:09
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 459 ms / 2,000 ms
コード長 1,034 bytes
コンパイル時間 655 ms
コンパイル使用メモリ 65,024 KB
実行使用メモリ 6,656 KB
最終ジャッジ日時 2024-10-01 22:58:32
合計ジャッジ時間 13,367 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 57
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
using namespace std;

long long mod = 1000000007;
long long N, M, X;
long long A[1 << 18], B[1 << 18];

long long modpow(long long a, long long b, long long m) {
	long long p = 1, q = a;
	for (int i = 0; i < 62; i++) {
		if ((b / (1LL << i)) % 2LL == 1) {
			p *= q; p %= m;
		}
		q *= q; q %= m;
	}
	return p;
}

int main() {
	// Step #1. 入力
	cin >> N >> M >> X;
	for (int i = 1; i <= N; i++) cin >> A[i];
	for (int i = 1; i <= M; i++) cin >> B[i];

	// Step #2. 計算
	long long Answer = 1;
	for (int i = 0; i < X; i++) {
		long long c0 = 0, c1 = 0, d0 = 0, d1 = 0;
		for (int j = 1; j <= N; j++) {
			if ((A[j] / (1LL << i)) % 2LL == 0) c0 += 1;
			if ((A[j] / (1LL << i)) % 2LL == 1) c1 += 1;
		}
		for (int j = 1; j <= M; j++) {
			if ((B[j] / (1LL << i)) % 2LL == 0) d0 += 1;
			if ((B[j] / (1LL << i)) % 2LL == 1) d1 += 1;
		}
		long long res = 0;
		if (c1 % 2LL == d1 % 2LL) {
			res = modpow(2LL, (N - 1) * (M - 1), mod);
		}
		Answer *= res;
		Answer %= mod;
	}
	cout << Answer << endl;
	return 0;
}
0