結果
| 問題 |
No.226 0-1パズル
|
| コンテスト | |
| ユーザー |
milanis48663220
|
| 提出日時 | 2019-09-16 17:13:48 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 2,117 bytes |
| コンパイル時間 | 418 ms |
| コンパイル使用メモリ | 55,792 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-26 14:24:48 |
| 合計ジャッジ時間 | 1,110 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 22 |
コンパイルメッセージ
main.cpp:7:6: warning: built-in function ‘pow’ declared as non-function [-Wbuiltin-declaration-mismatch]
7 | long pow[101];
| ^~~
ソースコード
#include <iostream>
using namespace std;
const long MOD = 1000000007;
long pow[101];
void init(){
pow[0] = 1;
for(int i = 1; i <= 100; i++){
pow[i] = pow[i-1]*2;
pow[i] %= MOD;
}
}
int main(){
init();
int H, W;
cin >> H >> W;
char s[100][100];
bool all_free = true;
for(int i = 0; i < H; i++){
for(int j = 0; j < W; j++){
cin >> s[i][j];
if(s[i][j] != '?') all_free = false;
}
}
int fc = 0, fr = 0;
int bc = 0, br = 0;
for(int i = 0; i < H; i++){
int type = -1;
for(int j = 0; j < W; j++){
if(s[i][j] == '0'){
if(j%2 == 0){
if(type == 1) br++;
else type = 0;
}else{
if(type == 0) br++;
else type = 1;
}
}
if(s[i][j] == '1'){
if(j%2 == 0){
if(type == 0) br++;
else type = 1;
}else{
if(type == 1) br++;
else type = 0;
}
}
}
if(type == -1) fr++;
}
long ans = 0;
if(br == 0) ans += pow[fr];
for(int j = 0; j < W; j++){
int type = -1;
for(int i = 0; i < H; i++){
if(s[i][j] == '0'){
if(i%2 == 0){
if(type == 1) bc++;
else type = 0;
}else{
if(type == 0) bc++;
else type = 1;
}
}
if(s[i][j] == '1'){
if(i%2 == 0){
if(type == 0) bc++;
else type = 1;
}else{
if(type == 1) bc++;
else type = 0;
}
}
}
if(type == -1) fc++;
}
if(bc == 0) ans += pow[fc];
if(bc == 0 && br == 0){
if(all_free) ans -= 2;
else ans -= 1;
}
ans %= MOD;
ans += MOD;
ans %= MOD;
cout << ans << endl;
}
milanis48663220