結果

問題 No.34 砂漠の行商人
ユーザー mkawa2mkawa2
提出日時 2020-01-08 11:09:43
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 101 ms / 5,000 ms
コード長 858 bytes
コンパイル時間 383 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 11,392 KB
最終ジャッジ日時 2024-05-02 12:36:58
合計ジャッジ時間 2,161 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
10,624 KB
testcase_01 AC 27 ms
10,752 KB
testcase_02 AC 32 ms
10,624 KB
testcase_03 AC 26 ms
10,752 KB
testcase_04 AC 34 ms
10,752 KB
testcase_05 AC 37 ms
10,752 KB
testcase_06 AC 34 ms
10,752 KB
testcase_07 AC 53 ms
10,752 KB
testcase_08 AC 55 ms
11,008 KB
testcase_09 AC 52 ms
10,880 KB
testcase_10 AC 39 ms
11,008 KB
testcase_11 AC 41 ms
11,136 KB
testcase_12 AC 31 ms
10,752 KB
testcase_13 AC 101 ms
11,264 KB
testcase_14 AC 97 ms
11,392 KB
testcase_15 AC 28 ms
10,752 KB
testcase_16 AC 34 ms
10,752 KB
testcase_17 AC 26 ms
10,880 KB
testcase_18 AC 28 ms
10,752 KB
testcase_19 AC 55 ms
11,264 KB
testcase_20 AC 75 ms
11,136 KB
testcase_21 AC 32 ms
10,880 KB
testcase_22 AC 32 ms
10,752 KB
testcase_23 AC 30 ms
10,880 KB
testcase_24 AC 86 ms
11,392 KB
testcase_25 AC 35 ms
10,752 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

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)]

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={}
    now[si,sj]=v
    cnt=1
    while now:
        #print(now)
        nxt={}
        for (i,j),hp in now.items():
            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[ni,nj]=nhp
        now=nxt
        cnt+=1
    print(-1)

main()
0