結果

問題 No.226 0-1パズル
ユーザー maine_honzukimaine_honzuki
提出日時 2020-12-25 15:57:17
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,447 bytes
コンパイル時間 1,974 ms
コンパイル使用メモリ 201,980 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-10-04 12:08:33
合計ジャッジ時間 2,911 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1000000007;

ll book(const int& H, const int& W, const vector<string>& S) {
    int cnt = 0;
    auto paper = [](char c, int i) {
        if (c == '?')
            return -1;
        return (int)(c == (i & 1 ? '0' : '1'));
    };
    for (auto& V : S) {
        int tmp = -1;
        for (int j = 0; j < W; j++) {
            int num = paper(V[j], j);
            if (tmp == -1)
                tmp = num;
            else if (V[j] != '?')
                if (num != tmp)
                    return 0;
        }
        cnt += tmp == -1;
    }
    ll ret = 1, bi = 2;
    while (cnt) {
        if (cnt & 1)
            (ret *= bi) %= mod;
        (bi *= bi) %= mod;
        cnt /= 2;
    }
    return ret;
}

int main() {
    int H, W;
    cin >> H >> W;
    vector<string> S(H);
    for (int i = 0; i < H; i++) {
        cin >> S[i];
    }
    int ans;

    ans = book(H, W, S);
    vector<string> T(W);
    for (int j = 0; j < W; j++) {
        for (int i = 0; i < H; i++) {
            T[j] += S[i][j];
        }
    }
    (ans += book(W, H, T)) %= mod;

    for (int k = 0; k < 2; k++) {
        bool flag = true;
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                if (S[i][j] - '0' == (i + j + k) % 2)
                    flag = false;
            }
        }
        ans -= flag;
    }

    cout << ans << endl;
}
0