結果

問題 No.2646 Cycle Maze
ユーザー Ekiben542Ekiben542
提出日時 2024-02-26 10:23:49
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,165 bytes
コンパイル時間 338 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 81,724 KB
最終ジャッジ日時 2024-02-26 10:24:01
合計ジャッジ時間 11,963 ms
ジャッジサーバーID
(参考情報)
judge14 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
53,460 KB
testcase_01 AC 37 ms
53,460 KB
testcase_02 AC 37 ms
53,460 KB
testcase_03 AC 37 ms
53,460 KB
testcase_04 AC 37 ms
53,460 KB
testcase_05 AC 38 ms
53,460 KB
testcase_06 WA -
testcase_07 AC 37 ms
53,460 KB
testcase_08 WA -
testcase_09 AC 38 ms
53,460 KB
testcase_10 AC 39 ms
53,460 KB
testcase_11 AC 38 ms
53,460 KB
testcase_12 WA -
testcase_13 AC 37 ms
53,460 KB
testcase_14 WA -
testcase_15 AC 41 ms
53,460 KB
testcase_16 WA -
testcase_17 AC 38 ms
53,460 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 38 ms
53,460 KB
testcase_21 AC 39 ms
53,460 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 42 ms
53,460 KB
testcase_25 AC 212 ms
76,996 KB
testcase_26 AC 199 ms
77,012 KB
testcase_27 AC 321 ms
78,796 KB
testcase_28 AC 121 ms
76,500 KB
testcase_29 AC 214 ms
77,140 KB
testcase_30 AC 172 ms
76,628 KB
testcase_31 AC 212 ms
77,252 KB
testcase_32 AC 94 ms
76,396 KB
testcase_33 AC 204 ms
77,260 KB
testcase_34 AC 235 ms
78,252 KB
testcase_35 AC 207 ms
77,140 KB
testcase_36 WA -
testcase_37 AC 296 ms
78,656 KB
testcase_38 AC 126 ms
76,336 KB
testcase_39 AC 166 ms
76,628 KB
testcase_40 AC 147 ms
76,500 KB
testcase_41 AC 203 ms
77,012 KB
testcase_42 AC 126 ms
76,444 KB
testcase_43 AC 106 ms
76,148 KB
testcase_44 AC 131 ms
76,300 KB
testcase_45 AC 520 ms
81,084 KB
testcase_46 AC 474 ms
80,828 KB
testcase_47 AC 611 ms
81,596 KB
testcase_48 AC 476 ms
80,828 KB
testcase_49 AC 594 ms
81,724 KB
testcase_50 AC 451 ms
80,688 KB
testcase_51 AC 497 ms
81,072 KB
testcase_52 AC 491 ms
81,072 KB
testcase_53 AC 536 ms
81,456 KB
testcase_54 AC 558 ms
81,456 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappop, heappush

H, W, T = map(int, input().split())
sy, sx = map(int, input().split())
gy, gx = map(int, input().split())
grid = [list(input()) for _ in range(H)]

sy -= 1
sx -= 1
gy -= 1
gx -= 1

# Check if the start or goal position is '0' right after input
if grid[sy][sx] == '0' or grid[gy][gx] == '0':
    print('No')
    exit()

dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]

def is_reachable(mid):
    INF = 10**18
    dist = [[INF]*W for _ in range(H)]
    dist[sy][sx] = 0
    heap = [(0, sy, sx)]

    while heap:
        d, y, x = heappop(heap)
        if d > dist[y][x]:
            continue
        for i in range(4):
            nx, ny = x + dx[i], y + dy[i]
            if nx < 0 or W <= nx or ny < 0 or H <= ny:
                continue
            cost = mid if grid[ny][nx] == '#' else 1
            if d + cost < dist[ny][nx]:
                dist[ny][nx] = d + cost
                heappush(heap, (d + cost, ny, nx))
    return dist[gy][gx] <= T

left, right = 1, T
while right - left > 1:
    mid = (left + right) // 2
    if is_reachable(mid):
        left = mid
    else:
        right = mid

print('Yes' if left != 1 else 'No')
0