結果
問題 | No.1638 Robot Maze |
ユーザー | yudai1102jp |
提出日時 | 2021-08-06 23:47:53 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 183 ms / 2,000 ms |
コード長 | 1,877 bytes |
コンパイル時間 | 167 ms |
コンパイル使用メモリ | 82,404 KB |
実行使用メモリ | 78,128 KB |
最終ジャッジ日時 | 2024-09-17 04:21:04 |
合計ジャッジ時間 | 5,692 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 41 ms
53,048 KB |
testcase_01 | AC | 37 ms
53,100 KB |
testcase_02 | AC | 37 ms
53,232 KB |
testcase_03 | AC | 116 ms
77,208 KB |
testcase_04 | AC | 38 ms
53,700 KB |
testcase_05 | AC | 39 ms
55,188 KB |
testcase_06 | AC | 39 ms
54,464 KB |
testcase_07 | AC | 38 ms
54,084 KB |
testcase_08 | AC | 40 ms
53,316 KB |
testcase_09 | AC | 39 ms
54,196 KB |
testcase_10 | AC | 39 ms
54,368 KB |
testcase_11 | AC | 40 ms
53,732 KB |
testcase_12 | AC | 39 ms
54,588 KB |
testcase_13 | AC | 37 ms
53,508 KB |
testcase_14 | AC | 102 ms
76,684 KB |
testcase_15 | AC | 95 ms
76,620 KB |
testcase_16 | AC | 94 ms
76,908 KB |
testcase_17 | AC | 105 ms
77,800 KB |
testcase_18 | AC | 40 ms
55,112 KB |
testcase_19 | AC | 95 ms
76,736 KB |
testcase_20 | AC | 97 ms
76,872 KB |
testcase_21 | AC | 61 ms
76,148 KB |
testcase_22 | AC | 61 ms
76,276 KB |
testcase_23 | AC | 59 ms
76,376 KB |
testcase_24 | AC | 59 ms
76,216 KB |
testcase_25 | AC | 58 ms
76,336 KB |
testcase_26 | AC | 63 ms
76,172 KB |
testcase_27 | AC | 64 ms
76,436 KB |
testcase_28 | AC | 64 ms
76,264 KB |
testcase_29 | AC | 64 ms
76,272 KB |
testcase_30 | AC | 36 ms
53,992 KB |
testcase_31 | AC | 34 ms
53,288 KB |
testcase_32 | AC | 111 ms
77,020 KB |
testcase_33 | AC | 117 ms
77,448 KB |
testcase_34 | AC | 101 ms
77,412 KB |
testcase_35 | AC | 128 ms
77,952 KB |
testcase_36 | AC | 132 ms
77,592 KB |
testcase_37 | AC | 106 ms
77,036 KB |
testcase_38 | AC | 112 ms
76,956 KB |
testcase_39 | AC | 110 ms
77,256 KB |
testcase_40 | AC | 132 ms
77,484 KB |
testcase_41 | AC | 111 ms
77,428 KB |
testcase_42 | AC | 130 ms
77,724 KB |
testcase_43 | AC | 183 ms
78,128 KB |
testcase_44 | AC | 137 ms
77,336 KB |
testcase_45 | AC | 128 ms
77,100 KB |
testcase_46 | AC | 120 ms
77,340 KB |
testcase_47 | AC | 105 ms
77,028 KB |
testcase_48 | AC | 124 ms
77,508 KB |
testcase_49 | AC | 107 ms
76,868 KB |
testcase_50 | AC | 117 ms
77,556 KB |
testcase_51 | AC | 124 ms
77,232 KB |
ソースコード
import sys import heapq sys.setrecursionlimit(10**6) # 再帰関数使う時有効 H, W = map(int, input().split()) U, D, R, L, K, P = map(int, input().split()) x, y, xt, yt = map(int, input().split()) start = [x-1, y-1] goal = [xt-1, yt-1] goal_n = goal[0]*W+goal[1] allow = [[1, 0], [0, 1], [-1, 0], [0, -1]] allow_cost = [D, R, U, L] C = [input() for i in range(H)] # def fps(now, cost): # if now == goal: # return cost # ans = 10**13+8 # for i in range(4): # nextx = now[0]+allow[i][0] # nexty = now[1]+allow[i][1] # if not (0 <= nextx < H and 0 <= nexty < W): # continue # if C[nextx][nexty] == '.': # new_cost = cost+allow_cost[i] # elif C[nextx][nexty] == '@': # new_cost = cost+allow_cost[i]+P # else: # continue # ans = min(ans, fps([nextx, nexty], new_cost)) # return ans dp = [[-1]*W for i in range(H)] dp[start[0]][start[1]] = 0 q = [] heapq.heapify(q) heapq.heappush(q, (0, start)) ok = set() while q: cost, now = heapq.heappop(q) # now_n = [now_n//W, now_n % W] now_n = now*W+now if now_n == goal_n: break ok.add(now[0]*W+now[1]) for i in range(4): nextx = now[0]+allow[i][0] nexty = now[1]+allow[i][1] if (not (0 <= nextx < H and 0 <= nexty < W)) or C[nextx][nexty] == '#' or nextx*W+nexty in ok: continue if C[nextx][nexty] == '.': new_cost = dp[now[0]][now[1]]+allow_cost[i] elif C[nextx][nexty] == '@': new_cost = dp[now[0]][now[1]]+allow_cost[i]+P if dp[nextx][nexty] == -1 or dp[nextx][nexty] > new_cost: dp[nextx][nexty] = new_cost heapq.heappush(q, (new_cost, [nextx, nexty])) if dp[goal[0]][goal[1]] <= K and dp[goal[0]][goal[1]] != -1: print('Yes') else: print('No')