結果
問題 |
No.226 0-1パズル
|
ユーザー |
![]() |
提出日時 | 2021-04-28 17:32:44 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 54 ms / 5,000 ms |
コード長 | 2,266 bytes |
コンパイル時間 | 610 ms |
コンパイル使用メモリ | 82,320 KB |
実行使用メモリ | 61,952 KB |
最終ジャッジ日時 | 2024-07-26 14:27:21 |
合計ジャッジ時間 | 2,013 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 22 |
ソースコード
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)