結果
| 問題 |
No.1599 Hikyaku
|
| コンテスト | |
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 20:16:24 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,918 bytes |
| コンパイル時間 | 196 ms |
| コンパイル使用メモリ | 82,544 KB |
| 実行使用メモリ | 122,228 KB |
| 最終ジャッジ日時 | 2025-06-12 20:18:45 |
| 合計ジャッジ時間 | 10,994 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 4 |
| other | AC * 1 WA * 4 TLE * 1 -- * 43 |
ソースコード
import sys
import heapq
def main():
input = sys.stdin.read().split()
idx = 0
X = int(input[idx]); idx +=1
Y = int(input[idx]); idx +=1
N = int(input[idx]); idx +=1
postmen = []
for _ in range(N):
x = int(input[idx]); idx +=1
y = int(input[idx]); idx +=1
v = int(input[idx]); idx +=1
postmen.append( (x, y, v) )
# Grid points (601 x 601)
# Initialize the minimal time for each grid point
INF = float('inf')
otime = [ [ INF for _ in range(601) ] for _ in range(601) ]
# Priority queue: (otime, x, y)
heap = []
# Postman 1 is at (x1, y1)
x1, y1, v1 = postmen[0]
otime[x1][y1] = 0
heapq.heappush(heap, (0, x1, y1))
# Directions: up, down, left, right
dirs = [ (-1,0), (1,0), (0,-1), (0,1) ]
while heap:
current_otime, x, y = heapq.heappop(heap)
if current_otime > otime[x][y]:
continue
for dx, dy in dirs:
nx = x + dx
ny = y + dy
if 1 <= nx <= 600 and 1 <= ny <= 600:
# Find the minimal speed at (x,y)
# Check if any postman is at (x,y)
min_speed = 0
for px, py, pv in postmen:
if px == x and py == y and pv > min_speed:
min_speed = pv
if min_speed == 0:
# No postman here, cannot move
continue
# Calculate the time to move to (nx, ny)
distance = 1000 # since it's adjacent
time = distance / min_speed
new_otime = current_otime + time
if new_otime < otime[nx][ny]:
otime[nx][ny] = new_otime
heapq.heappush(heap, (new_otime, nx, ny))
# The answer is otime[X][Y]
print("{0:.10f}".format(otime[X][Y]))
if __name__ == '__main__':
main()
gew1fw