結果

問題 No.2412 YOU Grow Bigger!
ユーザー flygonflygon
提出日時 2023-08-11 23:34:35
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,524 bytes
コンパイル時間 183 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 77,440 KB
最終ジャッジ日時 2024-04-29 14:47:05
合計ジャッジ時間 3,695 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
54,912 KB
testcase_01 AC 45 ms
54,656 KB
testcase_02 AC 46 ms
54,784 KB
testcase_03 AC 96 ms
76,928 KB
testcase_04 AC 102 ms
76,928 KB
testcase_05 AC 107 ms
77,184 KB
testcase_06 AC 118 ms
77,440 KB
testcase_07 AC 99 ms
76,800 KB
testcase_08 AC 121 ms
77,440 KB
testcase_09 AC 68 ms
72,320 KB
testcase_10 AC 97 ms
76,800 KB
testcase_11 AC 58 ms
66,048 KB
testcase_12 AC 48 ms
61,056 KB
testcase_13 AC 70 ms
72,576 KB
testcase_14 AC 99 ms
77,056 KB
testcase_15 AC 51 ms
64,256 KB
testcase_16 AC 72 ms
69,760 KB
testcase_17 AC 75 ms
71,424 KB
testcase_18 WA -
testcase_19 AC 56 ms
63,488 KB
testcase_20 AC 71 ms
68,864 KB
testcase_21 AC 71 ms
69,376 KB
testcase_22 AC 97 ms
76,800 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 96 ms
77,184 KB
testcase_26 AC 97 ms
77,312 KB
testcase_27 AC 88 ms
77,012 KB
testcase_28 AC 75 ms
71,808 KB
testcase_29 AC 58 ms
64,384 KB
testcase_30 AC 47 ms
54,656 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(5*10**5)
input = sys.stdin.readline
from collections import defaultdict, deque, Counter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right
from math import gcd

h,w = map(int,input().split())
s = [input().rstrip() for i in range(h)]

g = [[0]*(w-2) for i in range(h-2)]

for i in range(1,h-1):
    for j in range(1, w-1):
        ok = 1
        for dx in [0,-1,1]:
            for dy in [0,-1,1]:
                ok &= s[i+dx][j+dy] == "."
        g[i-1][j-1] = ok
    

def bfs(x,y,g):
    que = deque([(x,y)])
    depth = [[-1]*(w-2) for i in range(h-2)]
    depth[x][y] = 0
    while que:
        x,y = que.popleft()
        for dx in [1,0,-1]:
            for dy in [1,0,-1]:
                if dx == 0 and dy == 0: continue
                nx, ny = x+dx, y+dy
                if not (0<= nx < h-2 and 0<=ny<w-2): continue
                if not g[nx][ny]: continue
                if depth[nx][ny] == -1:
                    depth[nx][ny] = depth[x][y]+1
                    que.append((nx,ny))
    return depth

d = bfs(0,0,g)
if d[-1][-1] == -1:
    print(0)
else:
    gg = [g[i][::1] for i in range(h-2)]
    for i in [-1,0,1]:
        for j in [-1,0,1]:
            gg[2+i][1+j] = 0
    if bfs(0,0,gg)[-1][-1] == -1:
        print(1)
        exit()
    gg = [g[i][::1] for i in range(h-2)]
    for i in [-1,0,1]:
        for j in [-1,0,1]:
            gg[1+i][2+j] = 0
    if bfs(0,0,gg)[-1][-1] == -1:
        print(1)
        exit()
    
    print(2)
0