結果

問題 No.226 0-1パズル
ユーザー btkbtk
提出日時 2015-06-15 10:02:17
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,423 bytes
コンパイル時間 447 ms
コンパイル使用メモリ 54,860 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-10-04 12:07:33
合計ジャッジ時間 1,364 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 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,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 2 ms
4,380 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 2 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>

using namespace std;
typedef long long LL;
const LL mod=(LL)1e9+7;
bool change[100][100][2];
bool ichimatsu[100][2];
string masu[100];

int H,W;
int checkICHIMATSU(){
	LL res=1;
	for(int i=0;i<H;i++){
		int b;
		bool flag;
		flag=true;
		b=0;
		for(int j=0;j<W-1;j++){
			flag&=(change[i][j][b]&&change[i][j+1][1-b]);
			b=1-b;
		}
		ichimatsu[i][0]=flag;
		flag=true;
		b=1;
		for(int j=0;j<W-1;j++){
			flag&=(change[i][j][b]&&change[i][j+1][1-b]);
			b=1-b;
		}
		ichimatsu[i][1]=flag;
	}

	for(int i=0;i<H;i++){
		int cnt=0;
		for(int b=0;b<2;b++)
			if(ichimatsu[i][b])cnt++;
		res=(res*cnt)%mod;
	}
	int b=0;
	bool flag=true;
	for(int i=0;i<H-1;i++){
		flag&=(ichimatsu[i][b]&&ichimatsu[i+1][1-b]);
		b=1-b;
	}
	if(flag)res--;
	b=1;
	flag=true;
	for(int i=0;i<H-1;i++){
		flag&=(ichimatsu[i][b]&&ichimatsu[i+1][1-b]);
		b=1-b;
	}
	if(flag)res--;
	if(res<0)res+=mod;
	return res;
}
int main(){
	cin>>H>>W;
	for(int i=0;i<H;i++)
		cin>>masu[i];
	for(int i=0;i<H;i++)
		for(int j=0;j<W;j++){
			change[i][j][0]=(masu[i][j]!='1');
			change[i][j][1]=(masu[i][j]!='0');
		}
	LL x=checkICHIMATSU();
	for(int j=0;j<W;j++)
		for(int i=H-2;i>=0;i--){
			for(int b=0;b<2;b++)
				change[i][j][b]&=change[i+1][j][1-b];
		}
	LL res=1;
	for(int i=0;i<W;i++){
		int cnt=0;
		for(int b=0;b<2;b++){
			if(change[0][i][b])cnt++;
		}
		res=(res*cnt)%mod;

	}
	cout<<(res+x)%mod<<endl;
	return 0;
}
0