結果

問題 No.226 0-1パズル
ユーザー ayaoniayaoni
提出日時 2021-04-28 17:32:44
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 80 ms / 5,000 ms
コード長 2,266 bytes
コンパイル時間 465 ms
コンパイル使用メモリ 87,232 KB
実行使用メモリ 76,140 KB
最終ジャッジ日時 2023-10-04 12:08:43
合計ジャッジ時間 3,060 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
71,284 KB
testcase_01 AC 75 ms
71,108 KB
testcase_02 AC 70 ms
71,468 KB
testcase_03 AC 73 ms
71,396 KB
testcase_04 AC 76 ms
75,968 KB
testcase_05 AC 72 ms
71,436 KB
testcase_06 AC 72 ms
71,324 KB
testcase_07 AC 72 ms
71,328 KB
testcase_08 AC 70 ms
71,468 KB
testcase_09 AC 69 ms
71,268 KB
testcase_10 AC 72 ms
71,440 KB
testcase_11 AC 70 ms
71,604 KB
testcase_12 AC 71 ms
71,440 KB
testcase_13 AC 69 ms
71,372 KB
testcase_14 AC 70 ms
71,284 KB
testcase_15 AC 74 ms
71,108 KB
testcase_16 AC 71 ms
71,116 KB
testcase_17 AC 78 ms
76,108 KB
testcase_18 AC 78 ms
75,844 KB
testcase_19 AC 79 ms
76,116 KB
testcase_20 AC 80 ms
76,076 KB
testcase_21 AC 80 ms
76,140 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def LS2(): return list(sys.stdin.readline().rstrip())


H,W = MI()
X = [S() for _ in range(H)]
mod = 10**9+7


ans1 = 1  # 1列目が縞々
for j in range(W):
    zero,one,q = 0,0,0
    for i in range(H):
        x = X[i][j]
        if x == '?':
            q += 1
        else:
            x = int(x)
            if i % 2 == 0:
                if x == 0:
                    zero += 1
                else:
                    one += 1
            else:
                if x == 0:
                    one += 1
                else:
                    zero += 1
    a = 1
    if zero and one:
        a = 0
    elif zero == 0 and one == 0:
        a = 2
        
    ans1 *= a
    ans1 %= mod


ans2 = 1  # 1行目が縞々
for i in range(H):
    zero,one,q = 0,0,0
    for j in range(W):
        x = X[i][j]
        if x == '?':
            q += 1
        else:
            x = int(x)
            if j % 2 == 0:
                if x == 0:
                    zero += 1
                else:
                    one += 1
            else:
                if x == 0:
                    one += 1
                else:
                    zero += 1
    a = 1
    if zero and one:
        a = 0
    elif zero == 0 and one == 0:
        a = 2

    ans2 *= a
    ans2 %= mod


ans3 = 0  # 1行目,1列目が縞々

X1 = []
X2 = []
A = '01'*(W//2)+'0'*(W % 2)
for i in range(H):
    X1.append(A)
    if A[-1] == '0':
        A += '1'
    else:
        A += '0'
    A = A[1:]
    X2.append(A)

for i in range(H):
    for j in range(W):
        if X[i][j] != '?' and X1[i][j] != X[i][j]:
            break
    else:
        continue
    break
else:
    ans3 += 1

for i in range(H):
    for j in range(W):
        if X[i][j] != '?' and X2[i][j] != X[i][j]:
            break
    else:
        continue
    break
else:
    ans3 += 1


ans = ans1+ans2-ans3
ans %= mod
print(ans)
0