結果

問題 No.34 砂漠の行商人
ユーザー DrDrpilotDrDrpilot
提出日時 2022-02-10 13:54:42
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 801 bytes
コンパイル時間 910 ms
コンパイル使用メモリ 87,020 KB
実行使用メモリ 842,096 KB
最終ジャッジ日時 2023-09-08 03:02:13
合計ジャッジ時間 9,369 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 95 ms
71,264 KB
testcase_01 AC 93 ms
71,640 KB
testcase_02 AC 124 ms
77,760 KB
testcase_03 AC 90 ms
71,588 KB
testcase_04 AC 145 ms
81,484 KB
testcase_05 AC 194 ms
83,768 KB
testcase_06 AC 123 ms
77,832 KB
testcase_07 AC 206 ms
86,872 KB
testcase_08 AC 232 ms
92,140 KB
testcase_09 MLE -
testcase_10 MLE -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
n,v,sx,sy,gx,gy=map(int,input().split())
sx-=1;sy-=1;gx-=1;gy-=1
grid=[list(map(int,input().split())) for _ in range(n)]
inf=float('inf')
dst=[[inf]*n for _ in range(n)]
dy=[0,1,0,-1];dx=[1,0,-1,0]
visited=[[[False]*(v+1) for _ in range(n)] for _ in range(n)]
hp=[[0]*n for _ in range(n)]
q=deque()
q.append((0,sy,sx,v))
while q:
    d,y,x,h=q.popleft()
    if (y,x)==(gy,gx):
        print(d)
        exit()
    if visited[y][x][h]:
        continue
    visited[y][x][h]=True
    if hp[y][x]>=h:
        continue
    hp[y][x]=h
    for i in range(4):
        ny,nx=y+dy[i],x+dx[i]
        if 0<=ny<n and 0<=nx<n and h>grid[ny][nx]:
            nh=h-grid[ny][nx]
            if not visited[ny][nx][nh] and hp[ny][nx]<nh:
                q.append((d+1,ny,nx,nh))
print(-1)
0