結果

問題 No.34 砂漠の行商人
ユーザー DrDrpilotDrDrpilot
提出日時 2022-02-10 13:54:26
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
MLE  
実行時間 -
コード長 801 bytes
コンパイル時間 163 ms
コンパイル使用メモリ 11,036 KB
実行使用メモリ 796,244 KB
最終ジャッジ日時 2023-09-08 03:02:03
合計ジャッジ時間 24,186 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
217,420 KB
testcase_01 AC 20 ms
8,592 KB
testcase_02 AC 30 ms
8,952 KB
testcase_03 AC 20 ms
8,988 KB
testcase_04 AC 189 ms
11,724 KB
testcase_05 AC 411 ms
12,676 KB
testcase_06 AC 60 ms
8,984 KB
testcase_07 AC 735 ms
14,760 KB
testcase_08 AC 1,111 ms
18,624 KB
testcase_09 AC 4,818 ms
462,608 KB
testcase_10 MLE -
testcase_11 MLE -
testcase_12 AC 105 ms
11,800 KB
testcase_13 MLE -
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