結果

問題 No.34 砂漠の行商人
ユーザー mkawa2mkawa2
提出日時 2020-01-08 10:40:56
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 963 ms / 5,000 ms
コード長 1,028 bytes
コンパイル時間 252 ms
コンパイル使用メモリ 82,496 KB
実行使用メモリ 237,440 KB
最終ジャッジ日時 2024-05-02 12:32:10
合計ジャッジ時間 6,237 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
52,608 KB
testcase_01 AC 43 ms
52,224 KB
testcase_02 AC 59 ms
62,592 KB
testcase_03 AC 43 ms
52,480 KB
testcase_04 AC 90 ms
76,296 KB
testcase_05 AC 95 ms
76,672 KB
testcase_06 AC 62 ms
68,480 KB
testcase_07 AC 130 ms
78,720 KB
testcase_08 AC 143 ms
80,128 KB
testcase_09 AC 286 ms
105,344 KB
testcase_10 AC 75 ms
75,876 KB
testcase_11 AC 101 ms
76,848 KB
testcase_12 AC 66 ms
73,976 KB
testcase_13 AC 963 ms
237,440 KB
testcase_14 AC 662 ms
177,664 KB
testcase_15 AC 60 ms
63,488 KB
testcase_16 AC 96 ms
76,712 KB
testcase_17 AC 49 ms
58,880 KB
testcase_18 AC 62 ms
66,048 KB
testcase_19 AC 262 ms
103,088 KB
testcase_20 AC 363 ms
128,128 KB
testcase_21 AC 61 ms
64,128 KB
testcase_22 AC 62 ms
67,200 KB
testcase_23 AC 57 ms
62,976 KB
testcase_24 AC 446 ms
137,632 KB
testcase_25 AC 82 ms
76,928 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
dij = [(0, 1), (1, 0), (0, -1), (-1, 0)]

def main():
    n,v,sj,si,gj,gi=MI()
    sj, si, gj, gi=sj-1,si-1,gj-1,gi-1
    ll=LLI(n)
    maxhp=[[0]*n for _ in range(n)]
    now=[[v,si,sj]]
    cnt=1
    while now:
        #print(now)
        nxt=[]
        for hp,i,j in now:
            for ni,nj in [[i+1,j],[i-1,j],[i,j+1],[i,j-1]]:
                if ni<0 or nj<0 or ni>=n or nj>=n:continue
                nhp=hp-ll[ni][nj]
                if nhp<=maxhp[ni][nj]:continue
                if (ni,nj)==(gi,gj):
                    print(cnt)
                    exit()
                maxhp[ni][nj]=nhp
                nxt.append([nhp,ni,nj])
        now=nxt
        cnt+=1
    print(-1)

main()
0