結果

問題 No.226 0-1パズル
ユーザー KenDoiKenDoi
提出日時 2023-04-26 01:00:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 2,149 bytes
コンパイル時間 1,018 ms
コンパイル使用メモリ 105,696 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-10-04 12:09:05
合計ジャッジ時間 1,924 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <iostream>
#include <stack>
#include <queue>
#include <algorithm>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <cmath>
#include<sstream>
#include<list>
#include<iomanip>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <bitset>
#include <cassert>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
const int INF = 100000000;
const long long LINF = 3e18 + 7;
const int MAX_N = 10000010;
const int MAX_W = 10002;
const int MAX_ARRAYK = 100000;
double PI = 3.14159265358979323846;
//using ll = long long;

// https://drken1215.hatenablog.com/entry/2020/10/29/032500

int H, W;

long long mod = 1000000007;

// 左上を val とした市松模様が valid かどうか
bool valid(vector<string> v, int val) {
	for (int i = 0; i < v.size(); i++) {
		for (int j = 0; j < v[0].size(); j++) {
			if (v[i][j] == '0' && (i + j + val) % 2 == 1) return false;
			if (v[i][j] == '1' && (i + j + val) % 2 == 0) return false;
		}
	}
	return true;
}


// 最初の行としてありうるものの個数
long long solve(vector<string> v) {
	int fre = 0;
	for (int j = 0; j < v[0].size(); j++) {
		set<int> s;
		for (int i = 0; i < v.size(); i++) {
			if (v[i][j] == '0') {
				if (i % 2 == 0) {
					s.insert(0);
				}
				else {
					s.insert(1);
				}
			}
			else if(v[i][j] == '1') {
				if (i % 2 == 0) {
					s.insert(1);
				}
				else {
					s.insert(0);
				}
			}
		}
		if (s.size() == 2) {
			return 0LL;
		}
		if (s.size() == 0) {
			fre++;
		}
	}

	long long ans = 1LL;
	for (int i = 0; i < fre; i++) {
		ans = ans * 2LL;
		ans %= mod;
	}

	return ans;

}

int main() {

	cin >> H >> W;
	vector<string> S(H);
	for (int i = 0; i < H; i++) {
		cin >> S[i];
	}

	long long res = solve(S);

	vector<string> T(W, string(H, '?'));
	for (int j = 0; j < W; j++) {
		for (int i = 0; i < H; i++) {
			T[j][i] = S[i][j];
		}
	}

	res += solve(T);
	res %= mod;

	long long sub = 0LL;
	if (valid(S, 0)) {
		sub++;
	}
	if (valid(S, 1)) {
		sub++;
	}

	long long ans = (res + mod - sub) % mod;

	cout << ans << endl;

	
	return 0;
}
0