結果

問題 No.2412 YOU Grow Bigger!
ユーザー titiatitia
提出日時 2023-11-23 01:25:55
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,739 ms / 6,000 ms
コード長 1,598 bytes
コンパイル時間 245 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 83,244 KB
最終ジャッジ日時 2023-11-23 01:26:10
合計ジャッジ時間 13,979 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,460 KB
testcase_01 AC 36 ms
53,460 KB
testcase_02 AC 46 ms
64,424 KB
testcase_03 AC 1,285 ms
82,852 KB
testcase_04 AC 1,294 ms
82,980 KB
testcase_05 AC 869 ms
80,180 KB
testcase_06 AC 1,537 ms
81,732 KB
testcase_07 AC 1,346 ms
83,244 KB
testcase_08 AC 1,739 ms
81,968 KB
testcase_09 AC 50 ms
66,512 KB
testcase_10 AC 135 ms
76,328 KB
testcase_11 AC 49 ms
64,304 KB
testcase_12 AC 36 ms
53,460 KB
testcase_13 AC 171 ms
76,784 KB
testcase_14 AC 97 ms
76,200 KB
testcase_15 AC 33 ms
53,460 KB
testcase_16 AC 49 ms
64,428 KB
testcase_17 AC 57 ms
68,588 KB
testcase_18 AC 363 ms
77,048 KB
testcase_19 AC 32 ms
53,460 KB
testcase_20 AC 48 ms
66,504 KB
testcase_21 AC 162 ms
76,620 KB
testcase_22 AC 165 ms
76,564 KB
testcase_23 AC 491 ms
77,016 KB
testcase_24 AC 766 ms
77,992 KB
testcase_25 AC 535 ms
76,980 KB
testcase_26 AC 129 ms
76,536 KB
testcase_27 AC 95 ms
76,088 KB
testcase_28 AC 233 ms
76,752 KB
testcase_29 AC 33 ms
53,460 KB
testcase_30 AC 38 ms
59,444 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

H,W=map(int,input().split())
S=[list(input().strip()) for i in range(H)]

OK=[[0]*W for i in range(H)]
OK[2][2]=1
Q=[(2,2)]

while Q:
    x,y=Q.pop()

    for z,w in [(x+1,y),(x-1,y),(x,y+1),(x,y-1),(x+1,y+1),(x-1,y+1),(x+1,y-1),(x-1,y-1)]:
        if 2<=z<H and 2<=w<W and OK[z][w]==0:

            flag=1

            for x0 in range(3):
                for y0 in range(3):
                    if S[z-x0][w-y0]=="#":
                        flag=0
                        break

            if flag==1:
                OK[z][w]=1
                Q.append((z,w))

if OK[H-1][W-1]==0:
    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 S[i][j]=="#":
            continue
    
        S[i][j]="#"

        OK=[[0]*W for i in range(H)]
        OK[2][2]=1
        Q=[(2,2)]

        while Q:
            x,y=Q.pop()

            for z,w in [(x+1,y),(x-1,y),(x,y+1),(x,y-1),(x+1,y+1),(x-1,y+1),(x+1,y-1),(x-1,y-1)]:

                if 2<=z<H and 2<=w<W and OK[z][w]==0:

                    flag=1

                    for x0 in range(3):
                        for y0 in range(3):
                            if S[z-x0][w-y0]=="#":
                                flag=0
                                break

                    if flag==1:
                        OK[z][w]=1
                        Q.append((z,w))

        if OK[H-1][W-1]==0:
            print(1)
            exit()

        S[i][j]="."

print(2)
                
0