結果

問題 No.226 0-1パズル
ユーザー PachicobuePachicobue
提出日時 2018-11-21 01:25:37
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,510 bytes
コンパイル時間 1,968 ms
コンパイル使用メモリ 203,712 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-10-04 12:07:46
合計ジャッジ時間 2,952 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,380 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 2 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 2 ms
4,376 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 <bits/stdc++.h>
using ll = long long;
constexpr ll MOD = 1000000007;
int main()
{
    int H, W;
    std::cin >> H >> W;
    std::vector<std::string> S(H);
    for (int i = 0; i < H; i++) { std::cin >> S[i]; }
    ll ans = 1;
    for (int i = 0; i < H; i++) {
        bool odd = false, even = false;
        for (int j = 0; j < W; j++) {
            if (S[i][j] == '0') {
                (j % 2 == 0 ? even : odd) = true;
            } else if (S[i][j] == '1') {
                (j % 2 == 1 ? even : odd) = true;
            }
        }
        (ans *= (2 - odd - even)) %= MOD;
    }
    std::vector<ll> p(W + 1, 1);
    for (int i = 1; i <= W; i++) { p[i] = p[i - 1] * 2 % MOD; }
    auto solve = [&]() {
        std::string top(W, '?');
        bool odd = true, even = true;
        int h = W;
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                if (S[i][j] != '?') {
                    const char c = (i % 2 == 0 ? S[i][j] : '0' + ('1' - S[i][j]));
                    if (top[j] != '?' and top[j] != c) { return 0LL; }
                    h -= (top[j] == '?' ? 1 : 0), top[j] = c;
                    if (c == '0') {
                        (j % 2 == 0 ? even : odd) = false;
                    } else {
                        (j % 2 == 1 ? even : odd) = false;
                    }
                }
            }
        }
        return (p[h] + MOD - even - odd) % MOD;
    };
    std::cout << (ans + solve()) % MOD << std::endl;
    return 0;
}
0