結果

問題 No.226 0-1パズル
ユーザー mayoko_mayoko_
提出日時 2015-07-21 15:53:41
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,187 bytes
コンパイル時間 1,114 ms
コンパイル使用メモリ 78,344 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-22 20:56:27
合計ジャッジ時間 1,813 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
//#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
//#include<list>
#include<queue>
#include<deque>
#include<algorithm>
//#include<numeric>
#include<utility>
#include<complex>
//#include<memory>
#include<functional>
#include<cassert>
#include<set>

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef complex<double> C;

const int MAX = 111;
const ll MOD = 1e9+7;
int H, W;
string board[MAX];

ll calc() {
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (board[i][j] != '?') {
                for (int k = 0; k < H; k++) {
                    const int diff = abs(i-k) % 2;
                    int should = board[i][j] - '0';
                    if (diff == 1) should ^= 1;
                    char c = (char)('0'+should);
                    if (board[k][j] != '?' && board[k][j] != c) {
                        return 0;
                    }
                    board[k][j] = c;
                }
            }
        }
    }
//    for (int i = 0; i < H; i++) cout << board[i] << endl;
    ll ans = 1;
    for (int i = 0; i < W; i++) {
        if (board[0][i] == '?') (ans *= 2) %= MOD;
    }
    return ans;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> H >> W;
    for (int i = 0; i < H; i++) cin >> board[i];
    ll ans = 1;
    ll cnt = 0;
    for (int i = 0; i < H; i++) {
        // 101010的something
        int ok = 0; // 最初1, 最初0 でないと11
        for (int j = 0; j < W; j++) {
            if (board[i][j] == '0') {
                if (j%2) ok |= 2;
                else ok |= 1;
            }
            if (board[i][j] == '1') {
                if (j%2) ok |= 1;
                else ok |= 2;
            }
        }
        int tmp = 2-__builtin_popcount(ok);
        ans *= tmp;
        ans %= MOD;
        if (i == 0) cnt = tmp;
    }
//    cout << ans << endl;
    cout << (ans + calc()-cnt) % MOD << endl;
    return 0;
}
0