結果

問題 No.20 砂漠のオアシス
ユーザー ytftytft
提出日時 2022-11-03 17:08:34
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,061 ms / 5,000 ms
コード長 1,310 bytes
コンパイル時間 275 ms
コンパイル使用メモリ 87,044 KB
実行使用メモリ 107,396 KB
最終ジャッジ日時 2023-09-25 01:37:02
合計ジャッジ時間 8,524 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
71,412 KB
testcase_01 AC 91 ms
75,932 KB
testcase_02 AC 82 ms
75,596 KB
testcase_03 AC 166 ms
80,144 KB
testcase_04 AC 160 ms
79,960 KB
testcase_05 AC 1,061 ms
107,396 KB
testcase_06 AC 861 ms
103,124 KB
testcase_07 AC 881 ms
103,404 KB
testcase_08 AC 514 ms
100,880 KB
testcase_09 AC 878 ms
103,476 KB
testcase_10 AC 79 ms
71,180 KB
testcase_11 AC 75 ms
71,180 KB
testcase_12 AC 212 ms
80,688 KB
testcase_13 AC 196 ms
80,544 KB
testcase_14 AC 225 ms
82,080 KB
testcase_15 AC 215 ms
80,696 KB
testcase_16 AC 286 ms
83,208 KB
testcase_17 AC 264 ms
82,736 KB
testcase_18 AC 282 ms
83,168 KB
testcase_19 AC 295 ms
83,860 KB
testcase_20 AC 174 ms
78,792 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys,heapq
input=lambda:sys.stdin.readline().rstrip()
class node:
    def __init__(self,con):
        self.con=con
class directedWeightedGraph:
    def __init__(self,N,edges=[]):
        self.N=N
        self.nodes=[node([]) for i in range(N)]
        for i in edges:
            self.nodes[i[0]].append(i[1:])
    def connect(self,f,t,weight=0):
        self.nodes[f].con.append([t,weight])
    def dijkstra(self,start):
        ans=[float('inf') for i in range(self.N)]
        watch=[]
        heapq.heappush(watch, [0,start])
        while watch:
            cur=heapq.heappop(watch)
            if ans[cur[1]]==float('inf'):
                ans[cur[1]]=cur[0]
                for i in self.nodes[cur[1]].con:
                    heapq.heappush(watch,[i[1]+ans[cur[1]],i[0]])
        return ans
O=[]
N,V,*O=map(int,input().split())
O[0],O[1]=O[1]-1,O[0]-1
L=[list(map(int,input().split())) for i in range(N)]
G=directedWeightedGraph(N**2)
for i in range(N-1):
	for j in range(N):
		G.connect(i*N+j,i*N+j+N,L[i+1][j])
		G.connect(i*N+j+N,i*N+j,L[i][j])
		G.connect(j*N+i+1,j*N+i,L[j][i])
		G.connect(j*N+i,j*N+i+1,L[j][i+1])
A=G.dijkstra(0)
if A[N**2-1]<V:
	print('YES')
elif O[0]>-1 and V>A[O[0]*N+O[1]]:
	print(['NO','YES'][G.dijkstra(O[0]*N+O[1])[N**2-1]<(V-A[O[0]*N+O[1]])*2])
else:
	print('NO')
	
0