Submission #76261882


Source Code Expand

from collections import deque
from itertools import product

H, W = map(int, input().split())
S = [input() for i in range(H)]
if all("." not in s for s in S) or all("#" not in s for s in S):
    for _ in range(H):
        print("." * W)
    exit(0)
dp = [[None] * W for i in range(H)]
dq = deque()
for i, j in product(range(H), range(W)):
    if S[i][j] == "#":
        ok = False
        for di, dj in product(range(-1, 2), repeat=2):
            if di == dj == 0:
                continue
            ni, nj = i + di, j + dj
            if ni not in range(H):
                continue
            if nj not in range(W):
                continue
            if S[ni][nj] == ".":
                ok = True
        if ok:
            dp[i][j] = 0
            dq.append((i, j))
while dq:
    i, j = dq.popleft()
    for di, dj in product(range(-1, 2), repeat=2):
        if di == dj == 0:
            continue
        ni, nj = i + di, j + dj
        if ni not in range(H):
            continue
        if nj not in range(W):
            continue
        if dp[ni][nj] is None:
            dp[ni][nj] = dp[i][j] + 1
            dq.append((ni, nj))
for i in range(H):
    print("".join("#" if dp[i][j] % 2 == 0 else "." for j in range(W)))

Submission Info

Submission Time
Task D - Repeatedly Repainting
User shogo314
Language Python (PyPy 3.11-v7.3.20)
Score 425
Code Size 1278 Byte
Status AC
Exec Time 817 ms
Memory 190684 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 425 / 425
Status
AC × 3
AC × 41
Set Name Test Cases
Sample sample00.txt, sample01.txt, sample02.txt
All sample00.txt, sample01.txt, sample02.txt, testcase00.txt, testcase01.txt, testcase02.txt, testcase03.txt, testcase04.txt, testcase05.txt, testcase06.txt, testcase07.txt, testcase08.txt, testcase09.txt, testcase10.txt, testcase11.txt, testcase12.txt, testcase13.txt, testcase14.txt, testcase15.txt, testcase16.txt, testcase17.txt, testcase18.txt, testcase19.txt, testcase20.txt, testcase21.txt, testcase22.txt, testcase23.txt, testcase24.txt, testcase25.txt, testcase26.txt, testcase27.txt, testcase28.txt, testcase29.txt, testcase30.txt, testcase31.txt, testcase32.txt, testcase33.txt, testcase34.txt, testcase35.txt, testcase36.txt, testcase37.txt
Case Name Status Exec Time Memory
sample00.txt AC 62 ms 94136 KiB
sample01.txt AC 62 ms 93640 KiB
sample02.txt AC 62 ms 93916 KiB
testcase00.txt AC 62 ms 93756 KiB
testcase01.txt AC 62 ms 93724 KiB
testcase02.txt AC 62 ms 94032 KiB
testcase03.txt AC 62 ms 93580 KiB
testcase04.txt AC 63 ms 94000 KiB
testcase05.txt AC 94 ms 109272 KiB
testcase06.txt AC 64 ms 94268 KiB
testcase07.txt AC 75 ms 108120 KiB
testcase08.txt AC 82 ms 108792 KiB
testcase09.txt AC 92 ms 108964 KiB
testcase10.txt AC 80 ms 108748 KiB
testcase11.txt AC 84 ms 108848 KiB
testcase12.txt AC 73 ms 105964 KiB
testcase13.txt AC 64 ms 95008 KiB
testcase14.txt AC 86 ms 108912 KiB
testcase15.txt AC 69 ms 103104 KiB
testcase16.txt AC 67 ms 101856 KiB
testcase17.txt AC 80 ms 108948 KiB
testcase18.txt AC 627 ms 155728 KiB
testcase19.txt AC 669 ms 156628 KiB
testcase20.txt AC 607 ms 190684 KiB
testcase21.txt AC 83 ms 108744 KiB
testcase22.txt AC 102 ms 109196 KiB
testcase23.txt AC 95 ms 108944 KiB
testcase24.txt AC 112 ms 109860 KiB
testcase25.txt AC 408 ms 168072 KiB
testcase26.txt AC 548 ms 165828 KiB
testcase27.txt AC 569 ms 165424 KiB
testcase28.txt AC 767 ms 159032 KiB
testcase29.txt AC 817 ms 164980 KiB
testcase30.txt AC 465 ms 141412 KiB
testcase31.txt AC 441 ms 143212 KiB
testcase32.txt AC 419 ms 170360 KiB
testcase33.txt AC 489 ms 146948 KiB
testcase34.txt AC 708 ms 147288 KiB
testcase35.txt AC 705 ms 142464 KiB
testcase36.txt AC 762 ms 145108 KiB
testcase37.txt AC 708 ms 146496 KiB