結果

問題 No.226 0-1パズル
ユーザー milanis48663220milanis48663220
提出日時 2019-09-16 17:13:48
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 2,117 bytes
コンパイル時間 425 ms
コンパイル使用メモリ 53,272 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-10-04 12:07:57
合計ジャッジ時間 1,397 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,384 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:7:13: warning: built-in function ‘pow’ declared as non-function [-Wbuiltin-declaration-mismatch]
 long pow[101];
             ^

ソースコード

diff #

#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;
}
0