結果

問題 No.2412 YOU Grow Bigger!
ユーザー mymelochanmymelochan
提出日時 2023-08-11 22:29:37
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 249 ms / 6,000 ms
コード長 1,706 bytes
コンパイル時間 150 ms
コンパイル使用メモリ 82,024 KB
実行使用メモリ 77,600 KB
最終ジャッジ日時 2024-05-01 06:36:23
合計ジャッジ時間 4,336 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
55,316 KB
testcase_01 AC 44 ms
56,032 KB
testcase_02 AC 48 ms
62,088 KB
testcase_03 AC 188 ms
77,600 KB
testcase_04 AC 196 ms
77,076 KB
testcase_05 AC 202 ms
77,076 KB
testcase_06 AC 188 ms
77,304 KB
testcase_07 AC 190 ms
77,168 KB
testcase_08 AC 202 ms
77,500 KB
testcase_09 AC 57 ms
67,932 KB
testcase_10 AC 76 ms
76,632 KB
testcase_11 AC 53 ms
65,052 KB
testcase_12 AC 44 ms
56,084 KB
testcase_13 AC 81 ms
76,620 KB
testcase_14 AC 63 ms
69,080 KB
testcase_15 AC 45 ms
56,320 KB
testcase_16 AC 56 ms
66,356 KB
testcase_17 AC 64 ms
70,116 KB
testcase_18 AC 137 ms
76,624 KB
testcase_19 AC 44 ms
55,216 KB
testcase_20 AC 56 ms
66,104 KB
testcase_21 AC 85 ms
76,564 KB
testcase_22 AC 83 ms
76,860 KB
testcase_23 AC 244 ms
77,472 KB
testcase_24 AC 249 ms
77,296 KB
testcase_25 AC 124 ms
76,784 KB
testcase_26 AC 75 ms
76,532 KB
testcase_27 AC 66 ms
72,336 KB
testcase_28 AC 91 ms
76,680 KB
testcase_29 AC 43 ms
56,004 KB
testcase_30 AC 46 ms
61,264 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#############################################################

import sys
sys.setrecursionlimit(10**7)

from heapq import heappop,heappush
from collections import deque,defaultdict,Counter
from bisect import bisect_left, bisect_right
from itertools import product,combinations,permutations
from math import sin,cos
#from math import isqrt #DO NOT USE PyPy

ipt = sys.stdin.readline
iin = lambda :int(ipt())
lmin = lambda :list(map(int,ipt().split()))

#############################################################

H,W = lmin()
T = [list(input()) for _ in range(H)]

st = [(1,1)]


d = []
for i in range(-1,2):
    for j in range(-1,2):
        if i|j == 0:
            continue
        d.append((i,j))

def func(S):
    st = [(1,1)]
    visited = [[0]*W for _ in range(H)]

    while st:
        i,j = st.pop()
        if i == H-2 and j == W-2:
            return True
        for di,dj in d:
            ni = di+i
            nj = dj+j
            if 1<=ni<H-1 and 1<=nj<W-1:
                if visited[ni][nj]:
                    continue
                visited[ni][nj] = 1
                g = 0
                for ii in range(-1,2):
                    for jj in range(-1,2):
                        if S[ni+ii][nj+jj] == "#":
                            g = 1
                if g == 0:
                    st.append((ni,nj))

    return False

if not func(T):
    print(0)
    exit()

for i in range(H):
    for j in range(W):
        if i <= 2 and j <= 2:
            continue
        if i >= H-3 and j >= W-3:
            continue
        if T[i][j] == ".":
            T[i][j] = "#"
            if not func(T):
                print(1)
                exit()
            T[i][j] = "."

print(2)
0