結果

問題 No.2837 Flip Triomino
ユーザー 沙耶花沙耶花
提出日時 2024-08-09 21:49:29
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,376 bytes
コンパイル時間 4,223 ms
コンパイル使用メモリ 267,636 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-08-09 21:49:38
合計ジャッジ時間 7,474 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 RE -
testcase_03 AC 2 ms
6,940 KB
testcase_04 RE -
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 9 ms
6,940 KB
testcase_08 RE -
testcase_09 AC 7 ms
6,944 KB
testcase_10 AC 10 ms
6,944 KB
testcase_11 AC 10 ms
6,944 KB
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 AC 9 ms
6,944 KB
testcase_19 RE -
testcase_20 AC 8 ms
6,940 KB
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 AC 3 ms
6,944 KB
testcase_29 AC 3 ms
6,940 KB
testcase_30 RE -
testcase_31 AC 6 ms
6,944 KB
testcase_32 RE -
testcase_33 AC 8 ms
6,940 KB
testcase_34 RE -
testcase_35 AC 3 ms
6,940 KB
testcase_36 AC 7 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 1000000000000000001
void flip(char &a){
	if(a=='1')a = '0';
	else a = '1';
}
bool check(vector<string> s){
	int w = s[0].size();
	rep(i,s.size()){
		rep(j,s[i].size()-2){
			if(s[i][j]=='1'){
				rep(k,3)flip(s[i][j+k]);
			}
		}
		if(i!=s.size()-1){
			if(s[i].back()=='1'){
				flip(s[i].back());
				flip(s[i][w-2]);
				flip(s[i+1][w-1]);
			}
			if(s[i][w-2]=='1'){
				flip(s[i][w-2]);
				flip(s[i+1][w-2]);
				flip(s[i+1][w-1]);
			}
		}
	}
	return s==vector<string>(s.size(),string(w,'0'));
}

int main(){
	
	int h,w;
	cin>>h>>w;
	
	vector<string> s(h);
	rep(i,h)cin>>s[i];
	vector<pair<int,int>> p;
	rep(i,h){
		rep(j,w){
			if(s[i][j]=='?'){
				p.emplace_back(i,j);
			}
			else if(s[i][j]=='B')s[i][j] = '1';
			else s[i][j] = '0';
		}
	}
	if(p.size()>=8){
		assert(false);
		mint ans = mint(2).pow(p.size());
		ans /= 4;
		cout<<ans.val()<<endl;
	}
	else{
		mint ans = 0;
		rep(i,1<<p.size()){
			vector<string> t = s;
			rep(j,p.size()){
				if(i>>j&1){
					t[p[j].first][p[j].second] = '1';
				}
				else{
					t[p[j].first][p[j].second] = '0';
				}
			}
			if(check(t))ans++;
		}
		cout<<ans.val()<<endl;
	}
	
    return 0;
}
0