結果
問題 | No.2695 Warp Zone |
ユーザー |
|
提出日時 | 2024-03-22 21:53:31 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 208 ms / 2,000 ms |
コード長 | 1,042 bytes |
コンパイル時間 | 2,699 ms |
コンパイル使用メモリ | 224,932 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-09-30 11:22:31 |
合計ジャッジ時間 | 5,390 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 24 |
ソースコード
#include <bits/stdc++.h>using namespace std;int main() {ios_base::sync_with_stdio(false);cin.tie(nullptr);long long H,W; cin >> H >> W;int N; cin >> N;map<pair<int,int>,pair<int,int>> Graph;map<pair<int,int>,int> dist;for(int i=0; i<N; i++){int a,b,c,d; cin >> a >> b >> c >> d;Graph[{a,b}] = {c,d};dist[{a,b}] = 2e9+9; dist[{c,d}] = 2e9+9;}dist[{1,1}] = 0; dist[{H,W}] = 2e9+9;priority_queue<tuple<int,int,int>,vector<tuple<int,int,int>>,greater<>> Q;Q.push({0,1,1});while(Q.size()){auto [d,x,y] = Q.top(); Q.pop();if(dist[{x,y}] > d) continue;auto [x2,y2] = Graph[{x,y}];if(x2 != 0) if(dist[{x2,y2}] > d+1) dist[{x2,y2}] = d+1,Q.push({d+1,x2,y2});for(auto [p,d3] : dist){auto [x3,y3] = p;long long nc = d;nc += abs(x-x3); nc += abs(y-y3);if(nc < d3) dist[p] = nc,Q.push({nc,x3,y3});}}cout << dist[{H,W}] << endl;}