結果

問題 No.226 0-1パズル
ユーザー hotcoffeehotcoffee
提出日時 2024-03-15 07:32:22
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 38 ms / 5,000 ms
コード長 1,035 bytes
コンパイル時間 188 ms
コンパイル使用メモリ 11,904 KB
実行使用メモリ 10,112 KB
最終ジャッジ日時 2024-03-15 07:32:24
合計ジャッジ時間 2,414 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
10,112 KB
testcase_01 AC 29 ms
10,112 KB
testcase_02 AC 29 ms
10,112 KB
testcase_03 AC 28 ms
10,112 KB
testcase_04 AC 30 ms
10,112 KB
testcase_05 AC 29 ms
10,112 KB
testcase_06 AC 33 ms
10,112 KB
testcase_07 AC 29 ms
10,112 KB
testcase_08 AC 29 ms
10,112 KB
testcase_09 AC 28 ms
10,112 KB
testcase_10 AC 31 ms
10,112 KB
testcase_11 AC 38 ms
10,112 KB
testcase_12 AC 29 ms
10,112 KB
testcase_13 AC 31 ms
10,112 KB
testcase_14 AC 30 ms
10,112 KB
testcase_15 AC 29 ms
10,112 KB
testcase_16 AC 30 ms
10,112 KB
testcase_17 AC 30 ms
10,112 KB
testcase_18 AC 30 ms
10,112 KB
testcase_19 AC 32 ms
10,112 KB
testcase_20 AC 30 ms
10,112 KB
testcase_21 AC 30 ms
10,112 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

H, W = map(int, input().split())
table = {}
for i in range(H):
    for j, v in enumerate(list(input())):
        if v != '?':
            if i not in table:
                table[i] = {}
            table[i][j] = int(v)

exp1= H
exp2= W
dup = 2
chk = -1
v_chk = [-1] * W
for i, row in table.items():
    h_chk = -1
    for j, v in row.items():
        if chk == -1:
            chk = (i + j + v) % 2
            dup = 1
        else:
            if chk != (i + j + v) % 2:
                dup = 0
        if h_chk == -1:
            h_chk = (j + v) % 2
            if exp1 > 0: exp1 -= 1
        else:
            if h_chk != (j + v) % 2:
                exp1 = -1
        if v_chk[j] == -1:
            v_chk[j] = (i + v) % 2
            if exp2 > 0: exp2 -= 1
        else:
            if v_chk[j] != (i + v) % 2:
                exp2 = -1
    if exp1 == -1 and exp2 == -1:
        break

MOD = 1000000007
ans = 0
if exp1 != -1:
    ans += pow(2, exp1, MOD)
if exp2 != -1:
    ans += pow(2, exp2, MOD) - dup
    ans %= MOD
print(ans)
0