結果

問題 No.226 0-1パズル
ユーザー maspy
提出日時 2020-03-28 02:57:17
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 475 ms / 5,000 ms
コード長 918 bytes
コンパイル時間 101 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 44,396 KB
最終ジャッジ日時 2024-07-26 14:25:13
合計ジャッジ時間 11,443 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/ python3.8
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np

MOD = 10 ** 9 + 7

H, W = map(int, readline().split())
S = np.frombuffer(read(), 'S1').reshape(H, -1)[:, :W]
answer = 0
for _ in range(2):
    S = S.T
    p = 1
    for row in S:
        x = 0
        if np.all(row[::2] != b'0') and np.all(row[1::2] != b'1'):
            x += 1
        if np.all(row[::2] != b'1') and np.all(row[1::2] != b'0'):
            x += 1
        p *= x
    answer += p

if all((np.all(S[::2, ::2] != b'0'),
        np.all(S[1::2, 1::2] != b'0'),
        np.all(S[1::2, ::2] != b'1'),
        np.all(S[::2, 1::2] != b'1'))):
    answer -= 1

if all((np.all(S[::2, ::2] != b'1'),
        np.all(S[1::2, 1::2] != b'1'),
        np.all(S[1::2, ::2] != b'0'),
        np.all(S[::2, 1::2] != b'0'))):
    answer -= 1


print(answer % MOD)
0