結果
問題 | No.1638 Robot Maze |
ユーザー | ayaoni |
提出日時 | 2021-08-06 21:35:49 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 158 ms / 2,000 ms |
コード長 | 2,426 bytes |
コンパイル時間 | 150 ms |
コンパイル使用メモリ | 81,520 KB |
実行使用メモリ | 79,932 KB |
最終ジャッジ日時 | 2024-09-17 01:27:29 |
合計ジャッジ時間 | 6,437 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 47 ms
52,736 KB |
testcase_01 | AC | 44 ms
52,480 KB |
testcase_02 | AC | 44 ms
52,992 KB |
testcase_03 | AC | 134 ms
78,720 KB |
testcase_04 | AC | 43 ms
53,248 KB |
testcase_05 | AC | 43 ms
53,632 KB |
testcase_06 | AC | 43 ms
53,376 KB |
testcase_07 | AC | 43 ms
53,632 KB |
testcase_08 | AC | 45 ms
52,992 KB |
testcase_09 | AC | 43 ms
53,760 KB |
testcase_10 | AC | 42 ms
53,632 KB |
testcase_11 | AC | 48 ms
52,992 KB |
testcase_12 | AC | 42 ms
53,888 KB |
testcase_13 | AC | 43 ms
53,376 KB |
testcase_14 | AC | 118 ms
78,488 KB |
testcase_15 | AC | 112 ms
77,572 KB |
testcase_16 | AC | 111 ms
77,568 KB |
testcase_17 | AC | 105 ms
77,584 KB |
testcase_18 | AC | 63 ms
67,712 KB |
testcase_19 | AC | 113 ms
77,724 KB |
testcase_20 | AC | 112 ms
77,452 KB |
testcase_21 | AC | 71 ms
72,320 KB |
testcase_22 | AC | 72 ms
72,064 KB |
testcase_23 | AC | 73 ms
72,832 KB |
testcase_24 | AC | 72 ms
72,576 KB |
testcase_25 | AC | 73 ms
72,704 KB |
testcase_26 | AC | 91 ms
78,300 KB |
testcase_27 | AC | 87 ms
78,108 KB |
testcase_28 | AC | 89 ms
77,952 KB |
testcase_29 | AC | 86 ms
77,952 KB |
testcase_30 | AC | 45 ms
52,992 KB |
testcase_31 | AC | 44 ms
52,864 KB |
testcase_32 | AC | 129 ms
78,592 KB |
testcase_33 | AC | 132 ms
79,052 KB |
testcase_34 | AC | 128 ms
79,336 KB |
testcase_35 | AC | 129 ms
78,976 KB |
testcase_36 | AC | 134 ms
79,104 KB |
testcase_37 | AC | 124 ms
79,232 KB |
testcase_38 | AC | 140 ms
79,360 KB |
testcase_39 | AC | 133 ms
78,720 KB |
testcase_40 | AC | 146 ms
79,400 KB |
testcase_41 | AC | 140 ms
78,976 KB |
testcase_42 | AC | 138 ms
78,860 KB |
testcase_43 | AC | 158 ms
79,360 KB |
testcase_44 | AC | 142 ms
78,960 KB |
testcase_45 | AC | 155 ms
79,488 KB |
testcase_46 | AC | 137 ms
79,932 KB |
testcase_47 | AC | 131 ms
79,188 KB |
testcase_48 | AC | 138 ms
79,288 KB |
testcase_49 | AC | 135 ms
78,976 KB |
testcase_50 | AC | 130 ms
79,528 KB |
testcase_51 | AC | 133 ms
79,652 KB |
ソースコード
import sys,heapq sys.setrecursionlimit(10**7) def I(): return int(sys.stdin.readline().rstrip()) def MI(): return map(int,sys.stdin.readline().rstrip().split()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) def LI2(): return list(map(int,sys.stdin.readline().rstrip())) def S(): return sys.stdin.readline().rstrip() def LS(): return list(sys.stdin.readline().rstrip().split()) def LS2(): return list(sys.stdin.readline().rstrip()) class Dijkstra_list(): # 1-based def __init__(self,N): self.N = N self.edges = [[] for _ in range(N+1)] def add(self,u,v,d,directed=False): if directed is False: # 無向グラフの場合 self.edges[u].append((v,d)) self.edges[v].append((u,d)) else: # 有向グラフの場合 self.edges[u].append((v,d)) def delete(self,u,v): self.edges[u] = [_ for _ in self.edges[u] if _[0] != v] self.edges[v] = [_ for _ in self.edges[v] if _[0] != u] def search(self,s): # sから各頂点までの最短距離 inf = 10**18 dist = [inf]*(self.N+1) # prev = [-1]*(self.N+1) dist[s] = 0 q = [] heapq.heappush(q,(0,s)) flag = [0]*(self.N+1) while q: d,u = heapq.heappop(q) if flag[u]: continue flag[u] = 1 for v,dd in self.edges[u]: if flag[v]: continue new_d = d + dd if dist[v] > new_d: dist[v] = new_d heapq.heappush(q,(new_d,v)) # prev[v] = u return dist # return dist,prev H,W = MI() U,D,R,L,K,P = MI() xs,ys,xt,yt = MI() C = ['#'*(W+1)] for _ in range(H): C.append('#'+S()) Di = Dijkstra_list((H+1)*(W+1)) directions = [(-1,0,U),(1,0,D),(0,-1,L),(0,1,R)] for i in range(1,H+1): for j in range(1,W+1): k = (W+1)*i+j for di,dj,cost in directions: ni,nj = i+di,j+dj if not (1 <= ni <= H and 1 <= nj <= W): continue if C[ni][nj] == '#': continue n = (W+1)*ni+nj if C[ni][nj] == '.': Di.add(k,n,cost,directed=True) else: Di.add(k,n,cost+P,directed=True) d = Di.search((W+1)*xs+ys)[(W+1)*xt+yt] if d <= K: print('Yes') else: print('No')