結果

問題 No.20 砂漠のオアシス
ユーザー ytftytft
提出日時 2022-11-03 17:01:31
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,301 bytes
コンパイル時間 278 ms
コンパイル使用メモリ 87,312 KB
実行使用メモリ 107,772 KB
最終ジャッジ日時 2023-09-25 01:32:15
合計ジャッジ時間 8,755 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
権限があれば一括ダウンロードができます

ソースコード

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]-=1
O[1]-=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]>0 and V>A[O[0]*N+O[1]]:
	print(['No','Yes'][G.dijkstra(N**2-1)[O[0]*N+O[1]]<(V-A[O[0]*N+O[1]])*2])
else:
	print('No')
	
0