結果

問題 No.226 0-1パズル
ユーザー drken1215drken1215
提出日時 2015-05-30 00:51:50
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 2,486 bytes
コンパイル時間 553 ms
コンパイル使用メモリ 60,288 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-10-04 12:07:03
合計ジャッジ時間 1,709 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

#define MAXW 110
#define MAXH 110

const long long MOD = 1000000007;

int H, W;
string str[MAXH];
bool canZero[MAXW], canIchi[MAXW];        // can put 0/1 in (0, i) ?
bool canZeroIchi[MAXH], canIchiZero[MAXH];


int main() {
    while (cin >> H >> W) {
        for (int i = 0; i < H; ++i) cin >> str[i];
        
        // the first row is neither 010101010101... nor 10101010...
        long long res1 = 1;
        for (int i = 0; i < MAXW; ++i) canZero[i] = canIchi[i] = true;
        for (int i = 0; i < W; ++i) {
            for (int j = 0; j < H; ++j) {
                if (str[j][i] == '0') {
                    if (j & 1) canZero[i] = false;
                    else canIchi[i] = false;
                }
                else if (str[j][i] == '1') {
                    if (j & 1) canIchi[i] = false;
                    else canZero[i] = false;
                }
            }
            int con = 0;
            if (canZero[i]) ++con;
            if (canIchi[i]) ++con;
            (res1 *= con) %= MOD;
        }
        bool canStartZero = true, canStartIchi = true;
        for (int i = 0; i < W; ++i) {
            if (i & 1) {
                if (!canZero[i]) canStartIchi = false;
                if (!canIchi[i]) canStartZero = false;
            }
            else {
                if (!canZero[i]) canStartZero = false;
                if (!canIchi[i]) canStartIchi = false;
            }
        }
        if (canStartZero) --res1;
        if (canStartIchi) --res1;
        
        
        // the first row is 010101010101... or 10101010...
        long long res2 = 1;
        for (int i = 0; i < MAXH; ++i) canZeroIchi[i] = canIchiZero[i] = true;
        for (int i = 0; i < H; ++i) {
            for (int j = 0; j < W; ++j) {
                if (str[i][j] == '0') {
                    if (j & 1) canZeroIchi[i] = false;
                    else canIchiZero[i] = false;
                }
                else if (str[i][j] == '1') {
                    if (j & 1) canIchiZero[i] = false;
                    else canZeroIchi[i] = false;
                }
            }
            int con = 0;
            if (canZeroIchi[i]) ++con;
            if (canIchiZero[i]) ++con;
            (res2 *= con) %= MOD;
        }

        long long res = (res1 + res2) % MOD;
        cout << res << endl;
    }
}



0