結果

問題 No.226 0-1パズル
ユーザー chocoruskchocorusk
提出日時 2019-01-21 18:47:54
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,609 bytes
コンパイル時間 678 ms
コンパイル使用メモリ 94,488 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-10-04 12:07:48
合計ジャッジ時間 1,605 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD=1e9+7;
int h, w;
string s[100];
int main()
{
	cin>>h>>w;
	for(int i=0; i<h; i++) cin>>s[i];
	ll ans1=1, ans2=1;
	int a[100];
	fill(a, a+w, -1);
	bool nuee=0;
	for(int i=0; i<h; i++){
		for(int j=0; j<w; j++){
			if(s[i][j]!='?'){
				int a1=(int)(s[i][j]-'0')^(i&1);
				if(a[j]>=0 && a[j]!=a1){
					nuee=1;
					ans1=0;
					break;
				}
				a[j]=a1;
			}
		}
		if(nuee) break;
	}
	if(!nuee){
		for(int j=0; j<w; j++) if(a[j]==-1) ans1=ans1*2%MOD;
	}
	fill(a, a+h, -1); nuee=0;
	for(int i=0; i<h; i++){
		for(int j=0; j<w; j++){
			if(s[i][j]!='?'){
				int a1=(int)(s[i][j]-'0')^(j&1);
				if(a[i]>=0 && a[i]!=a1){
					nuee=1;
					ans2=0;
					break;
				}
				a[i]=a1;
			}
		}
		if(nuee) break;
	}
	if(!nuee){
		for(int i=0; i<h; i++) if(a[i]==-1) ans2=ans2*2%MOD;
	}
	ll ans3=0;
	nuee=0;
	for(int i=0; i<h; i++){
		for(int j=0; j<w; j++){
			if(s[i][j]!='?' && (s[i][j]-'0')!=((i+j)&1)){
				nuee=1;
				break;
			}
		}
		if(nuee) break;
	}
	if(!nuee) ans3++;
	nuee=0;
	for(int i=0; i<h; i++){
		for(int j=0; j<w; j++){
			if(s[i][j]!='?' && (s[i][j]-'0')!=(((i+j)&1)^1)){
				nuee=1;
				break;
			}
		}
		if(nuee) break;
	}
	if(!nuee) ans3++;
	cout<<(ans1+ans2-ans3+MOD)%MOD<<endl;
	return 0;
}
0