結果

問題 No.2838 Diagonals
ユーザー suosuo
提出日時 2024-07-11 19:14:58
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 156 ms / 2,000 ms
コード長 1,285 bytes
コンパイル時間 561 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 85,880 KB
最終ジャッジ日時 2024-07-11 19:15:02
合計ジャッジ時間 4,092 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
51,968 KB
testcase_01 AC 37 ms
52,096 KB
testcase_02 AC 41 ms
53,120 KB
testcase_03 AC 37 ms
52,096 KB
testcase_04 AC 39 ms
52,608 KB
testcase_05 AC 42 ms
51,968 KB
testcase_06 AC 53 ms
62,208 KB
testcase_07 AC 47 ms
61,312 KB
testcase_08 AC 85 ms
77,688 KB
testcase_09 AC 156 ms
79,104 KB
testcase_10 AC 113 ms
78,336 KB
testcase_11 AC 152 ms
82,304 KB
testcase_12 AC 155 ms
85,880 KB
testcase_13 AC 123 ms
78,532 KB
testcase_14 AC 83 ms
76,672 KB
testcase_15 AC 97 ms
71,212 KB
testcase_16 AC 70 ms
72,064 KB
testcase_17 AC 88 ms
76,416 KB
testcase_18 AC 111 ms
76,964 KB
testcase_19 AC 103 ms
76,928 KB
testcase_20 AC 105 ms
76,800 KB
testcase_21 AC 85 ms
76,196 KB
testcase_22 AC 90 ms
76,416 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def prop(i, j):
    if ok[i][j]:
        return

    st = [(i, j)]
    ok[i][j] = True
    d = [(x, y) for x in range(-1, 2) for y in range(-1, 2)]
    while st:
        i, j = st.pop()
        for di, dj in d:
            if not (0 <= i + di < n and 0 <= j + dj < m):
                continue
            if s[i + di][j + dj] == "#":
                continue
            if ok[i + di][j + dj]:
                continue
            ok[i + di][j + dj] = True
            st.append((i + di, j + dj))


n, m = map(int, input().split())
s = [input() for i in range(n)]
ok = [[False] * m for i in range(n)]
for i in range(n):
    if s[i][0] == ".":
        prop(i, 0)
    if s[i][-1] == ".":
        prop(i, m - 1)

for j in range(m):
    if s[0][j] == ".":
        prop(0, j)
    if s[-1][j] == ".":
        prop(n - 1, j)


cnt = 0
for i in range(n):
    for j in range(m):
        if s[i][j] == ".":
            if not ok[i][j]:
                cnt -= 1
                prop(i, j)
        else:
            cnt += 2
            if i == n - 1 or j == m - 1:
                continue
            for di, dj in [(0, 0), (0, 1), (1, 0), (1, 1)]:
                if s[i + di][j + dj] == ".":
                    break
            else:
                cnt -= 1

print(pow(2, cnt, 998244353))
0