結果
問題 |
No.3116 More and more teleporter
|
ユーザー |
|
提出日時 | 2025-04-20 11:19:18 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 259 ms / 2,000 ms |
コード長 | 1,079 bytes |
コンパイル時間 | 1,871 ms |
コンパイル使用メモリ | 195,320 KB |
実行使用メモリ | 7,844 KB |
最終ジャッジ日時 | 2025-04-20 11:19:25 |
合計ジャッジ時間 | 5,414 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 22 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll INF = 1LL << 60; int main() { int N, Q; cin >> N >> Q; vector<ll> dist(N + 1); for (int i = 1; i <= N; ++i) dist[i] = i - 1; // 初期状態:1歩ずつ歩く while (Q--) { int type; cin >> type; if (type == 1) { int x; cin >> x; cout << dist[x] << endl; } else { int x; ll c; cin >> x >> c; // テレポーター設置 if (dist[x] > c) { dist[x] = c; // 1回の伝播でよい for (int i = x - 1; i >= 1; --i) { if (dist[i] > dist[i + 1] + 1) dist[i] = dist[i + 1] + 1; else break; } for (int i = x + 1; i <= N; ++i) { if (dist[i] > dist[i - 1] + 1) dist[i] = dist[i - 1] + 1; else break; } } } } }