結果
問題 |
No.2695 Warp Zone
|
ユーザー |
![]() |
提出日時 | 2025-09-10 13:06:52 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 29 ms / 2,000 ms |
コード長 | 1,940 bytes |
コンパイル時間 | 3,843 ms |
コンパイル使用メモリ | 191,932 KB |
実行使用メモリ | 23,552 KB |
最終ジャッジ日時 | 2025-09-10 13:06:58 |
合計ジャッジ時間 | 5,764 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 24 |
ソースコード
#include <iostream> #include <vector> #include <algorithm> #include <cmath> #include <queue> #include <atcoder/all> using namespace std; using namespace atcoder; using ll = long long; using mint = modint998244353; using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>; using vll = vector<ll>; using vvll = vector<vll>; using vvvll = vector<vvll>; using vmi = vector<mint>; using vvmi = vector<vmi>; using vvvmi = vector<vvmi>; #define all(a) (a).begin(), (a).end() #define rep2(i, m, n) for (int i = (m); i < (n); ++i) #define rep(i, n) rep2(i, 0, n) #define drep2(i, m, n) for (int i = (m)-1; i >= (n); --i) #define drep(i, n) drep2(i, n, 0) using p = pair<int, int>; int inf = 2e9+7; int main(){ int h, w, n; cin >> h >> w >> n; vector<p> vst(n), vg(n); rep(i, n){ int a, b, c, d; cin >> a >> b >> c >> d; vst[i] = {a, b}; vg[i] = {c, d}; } vvi dist(2*n+2, vi(2*n+2, inf)); p goal = {h, w}; rep(i, n){ auto [c, d] = vg[i]; dist[i][i+n] = 1; dist[i+n][2*n+1] = h+w-c-d; rep(j, n){ auto [a, b] = vst[j]; dist[i+n][j] = abs(c-a) + abs(d-b); } } rep(i, n){ auto [a, b] = vst[i]; dist[2*n][i] = a+b-2; dist[i][2*n+1] = h+w-a-b; } dist[2*n][2*n+1] = h+w-2; vvi adj(2*n+2); rep(i, 2*n+2){ rep(j, 2*n+2){ if(dist[i][j] < inf)adj[i].push_back(j); } } vi ans(2*n+2, inf); ans[2*n] = 0; priority_queue<p, vector<p>, greater<p>> pq; pq.push({0, 2*n}); while(!pq.empty()){ p u = pq.top(); pq.pop(); if(u.first > ans[u.second])continue; for(auto v : adj[u.second]){ int alt = u.first + dist[u.second][v]; if(alt < ans[v]){ ans[v] = alt; pq.push({alt, v}); } } } cout << ans[2*n+1] << endl; return 0; }