結果
| 問題 |
No.3116 More and more teleporter
|
| コンテスト | |
| ユーザー |
ciffelia
|
| 提出日時 | 2025-04-20 16:48:25 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 738 ms / 2,000 ms |
| コード長 | 911 bytes |
| コンパイル時間 | 516 ms |
| コンパイル使用メモリ | 12,288 KB |
| 実行使用メモリ | 23,680 KB |
| 最終ジャッジ日時 | 2025-04-20 16:48:35 |
| 合計ジャッジ時間 | 9,663 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 22 |
ソースコード
import sys
input = sys.stdin.readline
N, Q = map(int, input().split())
INF = 10**18
dp = [INF] * (N + 1)
dp[1] = 0
for i in range(2, N + 1):
dp[i] = dp[i-1] + 1
res = []
for _ in range(Q):
tmp = input().split()
if tmp[0] == "1":
x = int(tmp[1])
res.append(dp[x])
else:
x = int(tmp[1])
c = int(tmp[2])
if c < dp[x]:
before = dp[x]
dp[x] = c
# 前方: xより右にc+1, c+2..の候補が無ければcost更新
for i in range(x+1, N+1):
if dp[i] > dp[i-1] + 1:
dp[i] = dp[i-1] + 1
else:
break
# 後方: xより左に同様
for i in range(x-1, 0, -1):
if dp[i] > dp[i+1] + 1:
dp[i] = dp[i+1] + 1
else:
break
print('\n'.join(map(str, res)))
ciffelia