結果
問題 |
No.3116 More and more teleporter
|
ユーザー |
|
提出日時 | 2025-04-20 17:51:29 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 58 ms / 2,000 ms |
コード長 | 1,222 bytes |
コンパイル時間 | 2,339 ms |
コンパイル使用メモリ | 201,548 KB |
実行使用メモリ | 7,848 KB |
最終ジャッジ日時 | 2025-04-20 17:51:34 |
合計ジャッジ時間 | 4,222 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 22 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll INF = 1LL << 60; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N, Q; cin >> N >> Q; vector<ll> cost(N + 1, INF); cost[1] = 0; priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<>> pq; pq.emplace(0, 1); while (Q--) { int type; cin >> type; if (type == 1) { int x; cin >> x; while (!pq.empty()) { auto [c, pos] = pq.top(); pq.pop(); if (c > cost[pos]) continue; for (int d : {-1, 1}) { int nx = pos + d; if (nx < 1 || nx > N) continue; if (cost[nx] > cost[pos] + 1) { cost[nx] = cost[pos] + 1; pq.emplace(cost[nx], nx); } } } cout << cost[x] << '\n'; } else { int x; ll c; cin >> x >> c; if (cost[x] > c) { cost[x] = c; pq.emplace(c, x); } } } return 0; }