結果

問題 No.226 0-1パズル
ユーザー batasanblogbatasanblog
提出日時 2023-06-25 20:43:03
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 2,607 bytes
コンパイル時間 4,321 ms
コンパイル使用メモリ 264,056 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-10-04 12:09:10
合計ジャッジ時間 5,259 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
//using mint = static_modint<998244353>;
//using mint = modint;
using mint = static_modint<1000000007>;
using vm = vector<mint>;
using vvm = vector<vm>;
ostream &operator<<(ostream &o,const mint &m){cout<<m.val();return o;}
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using pl = pair<ll,ll>;
using vp = vector<pl>;
#define rep(i,n) for(ll i=0;i<(ll)(n);++i)
#define reps(i,s,n) for(ll i=(s);i<(ll)(n);++i)
#define rep1(i,n) for(ll i=1;i<=(ll)(n);++i)
template<typename T>inline bool chmax(T &a,T b){return a<b?a=b,true:false;}
template<typename T>inline bool chmin(T &a,T b){return a>b?a=b,true:false;}
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define be(v) (v).begin(),(v).end()
const long long INF = 1e18;
#ifdef DEBUG
#include <debug.hpp>
random_device rd;
mt19937 gen(rd());
ll random(ll l,ll h){
	uniform_int_distribution<ll> dist(l,h);
	return dist(gen);
}
#endif

ll H,W;
vector<string> S,R;
void input(){
	cin>>H>>W;
	S.assign(H,string());
	R.assign(W,string());
	rep(h,H){
		cin>>S.at(h);
		rep(w,W){
			R.at(w).pb(S.at(h).at(w));
		}
	}
}
#ifdef DEBUG
void showall(){
	show(H,W,S,R);
}
#endif
ll ichimatsu(vector<string> vs){
	bool od=false, ev=false;
	rep(i,vs.size())rep(j,vs.at(i).size()){
		char c = vs.at(i).at(j);
		if(c == '0'){
			if((i + j)%2) ev=true;
			else od=true;
		}else if(c == '1'){
			if((i + j)%2) od=true;
			else ev=true;
		}
	}
	if(od && ev) return 0;
	if(!od && !ev) return 2;
	else return 1;	
}
mint check(vector<string> vs){
	ll cnt=0;
	for(auto s:vs){
		bool od=false, ev=false;
		rep(i,s.size()){
			if(s.at(i) == '0'){
				if(i%2) ev=true;
				else od=true;
			}else if(s.at(i) == '1'){
				if(i%2) od=true;
				else ev=true;
			}
		}
		if(od && ev) return 0;
		if(!od && !ev) ++cnt;
	}
	return mint(2).pow(cnt);
}
void logic(){
	mint ans = check(S);
	ans += check(R);
	ans -= ichimatsu(S);
	cout<<ans<<endl;
}
#ifdef DEBUG
ll naive(){
	return 1;
}
#endif
int main(){
	#ifdef DEBUG
	cout << "--- Input ---" << endl;
	#endif
	input();
	#ifdef DEBUG
	showall();
	cout << "--- Logic ---" << endl;
	#endif
	logic();
	#ifdef DEBUG
	cout << "--- Answer ---" << endl;
	#endif
	//cout<<ans<<endl;
	//while(input())logic();
	#ifdef DEBUG
	//show("naive=",naive());
	#endif
	#ifdef DEBUG
	/*
	rep(q,100){
		N=random(1LL,1000LL);
		ll lans=logic(),nans=naive();
		showall();
		if(lans!=nans){ show(" WA",lans,nans); break; }
		else{ show(" AC",lans,nans); }
	}
	*/
	#endif
	return 0;
}
//cout << fixed << setprecision(9);
0