結果

問題 No.226 0-1パズル
ユーザー asumo0729asumo0729
提出日時 2022-07-12 23:07:51
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 116 ms / 5,000 ms
コード長 2,465 bytes
コンパイル時間 281 ms
コンパイル使用メモリ 87,164 KB
実行使用メモリ 77,440 KB
最終ジャッジ日時 2023-10-04 12:08:54
合計ジャッジ時間 3,787 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 105 ms
72,976 KB
testcase_01 AC 109 ms
72,576 KB
testcase_02 AC 105 ms
72,648 KB
testcase_03 AC 102 ms
72,332 KB
testcase_04 AC 111 ms
77,440 KB
testcase_05 AC 106 ms
72,500 KB
testcase_06 AC 107 ms
72,488 KB
testcase_07 AC 107 ms
72,872 KB
testcase_08 AC 105 ms
72,540 KB
testcase_09 AC 107 ms
72,896 KB
testcase_10 AC 107 ms
72,340 KB
testcase_11 AC 107 ms
72,676 KB
testcase_12 AC 107 ms
72,532 KB
testcase_13 AC 108 ms
72,332 KB
testcase_14 AC 113 ms
72,328 KB
testcase_15 AC 107 ms
72,368 KB
testcase_16 AC 106 ms
72,688 KB
testcase_17 AC 114 ms
77,368 KB
testcase_18 AC 116 ms
77,324 KB
testcase_19 AC 115 ms
77,044 KB
testcase_20 AC 115 ms
77,148 KB
testcase_21 AC 116 ms
77,324 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from operator import itemgetter
from collections import defaultdict, deque
import heapq
from heapq import heapify, heappop, _heapify_max, heappush
from bisect import bisect_left, bisect_right
import math
import itertools
import copy

stdin=sys.stdin
#sys.setrecursionlimit(10 ** 7)
## import pypyjit
## pypyjit.set_param('max_unroll_recursion=-1')

ip=lambda: int(sp())
fp=lambda: float(sp())
lp=lambda:list(map(int,stdin.readline().split()))
sp=lambda:stdin.readline().rstrip()
Yp=lambda:print('Yes')
Np=lambda:print('No')
inf = 1 << 60
inf = float('inf')
mod = 10 ** 9 + 7
#mod = 998244353
eps = 1e-9
sortkey1 = itemgetter(0)
sortkey2 = lambda x: (x[0], x[1])



###############################################################

H, W = lp()
S = [sp() for _ in range(H)]
#dp[0]=01010.. dp[1]=101010... dp[2]=その他

ans = 0
#連続部分なし
a = 0
b = 0

s01 = []
s10 = []
for w in range(W):
    if w & 1:
        s01.append('1')
        s10.append('0')
    else:
        s01.append('0')
        s10.append('1')

for h in range(H):
    bla = True; blb = True
    for w in range(W):
        if S[h][w] != '?' and S[h][w] != s01[w]:
            bla = False
        if S[h][w] != '?' and S[h][w] != s10[w]:
            blb = False
    if h == 0:
        if bla:
            a = 1
        if blb:
            b = 1
    else:
        if bla:
            aa = a + b
        else:
            aa = 0
        if blb:
            bb = a + b
        else:
            bb = 0
        a = aa % mod; b = bb % mod
        
ans = a + b

ans %= mod
first = []
for w in range(W):
    x = '?'
    for h in range(H - 1, 0, -1):
        if S[h][w] != '?':
            if x != '?' and x != S[h][w]:
                print(ans)
                exit()
            else:
                x = S[h][w]
        if x != '?':
            x = '0' if x == '1' else '1'
    first.append(x)
res = 1

for w in range(W):
    if first[w] != '?' and S[0][w] != '?' and first[w] != S[0][w]:
        print(ans)
        exit()
    elif first[w] == '?' and S[0][w] == '?':
        res *= 2
        res %= mod

bla = True; blb = True
for w in range(W):
    if first[w] != '?' and first[w] != s01[w]:
        bla = False
    if S[0][w] != '?' and S[0][w] != s01[w]:
        bla = False

    if first[w] != '?' and first[w] != s10[w]:
        blb = False
    if S[0][w] != '?' and S[0][w] != s10[w]:
        blb = False
if bla:
    res -= 1
if blb:
    res -= 1
ans += res 
ans %= mod
print(ans)
0