結果

問題 No.226 0-1パズル
ユーザー maspymaspy
提出日時 2020-03-28 02:57:17
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 144 ms / 5,000 ms
コード長 918 bytes
コンパイル時間 106 ms
コンパイル使用メモリ 10,908 KB
実行使用メモリ 29,732 KB
最終ジャッジ日時 2023-10-04 12:08:07
合計ジャッジ時間 4,316 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 134 ms
29,596 KB
testcase_01 AC 135 ms
29,644 KB
testcase_02 AC 136 ms
29,680 KB
testcase_03 AC 137 ms
29,660 KB
testcase_04 AC 140 ms
29,732 KB
testcase_05 AC 135 ms
29,676 KB
testcase_06 AC 135 ms
29,700 KB
testcase_07 AC 134 ms
29,712 KB
testcase_08 AC 134 ms
29,660 KB
testcase_09 AC 135 ms
29,660 KB
testcase_10 AC 133 ms
29,708 KB
testcase_11 AC 135 ms
29,696 KB
testcase_12 AC 137 ms
29,704 KB
testcase_13 AC 137 ms
29,696 KB
testcase_14 AC 135 ms
29,652 KB
testcase_15 AC 136 ms
29,640 KB
testcase_16 AC 135 ms
29,648 KB
testcase_17 AC 139 ms
29,660 KB
testcase_18 AC 140 ms
29,596 KB
testcase_19 AC 140 ms
29,696 KB
testcase_20 AC 143 ms
29,668 KB
testcase_21 AC 144 ms
29,644 KB
権限があれば一括ダウンロードができます

ソースコード

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