結果

問題 No.226 0-1パズル
ユーザー msm1993msm1993
提出日時 2020-06-01 11:35:52
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,021 bytes
コンパイル時間 204 ms
コンパイル使用メモリ 33,216 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-10-04 12:08:07
合計ジャッジ時間 1,175 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

int main()
{
	int n, m, c = 0, d = 0; char b[111][111];
	scanf ("%d %d", &n, &m);
	for (int i = 0; i < n; i++){
		scanf ("%s", b[i]);
		for (int j = 0; j < m; j++) if (b[i][j] != '?'){
			c += (b[i][j] - '0' + i + j) % 2;
			d++;
		}
	}

	int u = 0;
	for (int i = 0; i < n; i++){
		int c[2] = { 0, };
		for (int j = 0; j < m; j++) if (b[i][j] != '?'){
			c[(b[i][j] - '0' + j) % 2]++;
		}
		if (c[0] && c[1]){
			u = -1; break;
		}
		if (!c[0] && !c[1]) u++;
	}

	int v = 0;
	for (int j = 0; j < m; j++){
		int c[2] = { 0, };
		for (int i = 0; i < n; i++) if (b[i][j] != '?'){
			c[(b[i][j] - '0' + i) % 2]++;
		}
		if (c[0] && c[1]){
			v = -1; break;
		}
		if (!c[0] && !c[1]) v++;
	}

	const long long mod = 1000000007;
	long long U = 1, V = 1;
	if (u < 0) U = 0;
	else while (u--) U = U * 2 % mod;
	if (v < 0) V = 0;
	else while (v--) V = V * 2 % mod;

	long long A = (U + V) % mod;
	if (c == 0) A = (A + mod - 1) % mod;
	if (c == d) A = (A + mod - 1) % mod;
	
	printf ("%lld\n", A);

	return 0;
}
0