結果
| 問題 |
No.3116 More and more teleporter
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-05-23 07:24:37 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,230 bytes |
| コンパイル時間 | 318 ms |
| コンパイル使用メモリ | 12,032 KB |
| 実行使用メモリ | 26,568 KB |
| 最終ジャッジ日時 | 2025-05-23 07:24:45 |
| 合計ジャッジ時間 | 8,008 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | TLE * 1 -- * 21 |
ソースコード
import sys
input = sys.stdin.readline
N, Q = map(int, input().split())
# テレポーター情報を格納
# teleporters[position] = cost
teleporters = {}
for _ in range(Q):
query = list(map(int, input().split()))
if query[0] == 1:
# クエリ1: マス1からマスxへの最小コスト
x = query[1]
# 直接歩く場合のコスト
min_cost = x - 1
# テレポーターを使う場合
for pos, tp_cost in teleporters.items():
# どこからでもテレポーターを使えるので、
# マス1からテレポーター位置まで歩く必要はない
# テレポートでマスposに移動し、そこからマスxまで歩く
total_cost = tp_cost + abs(x - pos)
min_cost = min(min_cost, total_cost)
print(min_cost)
else:
# クエリ2: マスxにコストcのテレポーター設置
x = query[1]
c = query[2]
# 既存のテレポーターがある場合は、より安いものに更新
if x not in teleporters:
teleporters[x] = c
else:
teleporters[x] = min(teleporters[x], c)