結果
| 問題 | No.2695 Warp Zone |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-11-02 10:20:51 |
| 言語 | C++23(gcc16) (gcc 16.2.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 156 ms / 2,000 ms |
| + 434µs | |
| コード長 | 1,335 bytes |
| 記録 | |
| コンパイル時間 | 2,116 ms |
| コンパイル使用メモリ | 198,616 KB |
| 実行使用メモリ | 51,868 KB |
| 最終ジャッジ日時 | 2026-11-02 10:20:59 |
| 合計ジャッジ時間 | 3,562 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 25 |
ソースコード
#include <iostream>
#include <vector>
#include <queue>
#include <utility>
using namespace std;
using ll = long long;
using Graph = vector<vector<pair<int, ll>>>;
using pli = pair<ll, int>;
struct point{
ll x, y;
ll distance(point q){
return abs(x-q.x)+abs(y-q.y);
}
};
const ll INF = 1LL<<60;
int N;
point pos[2010];
ll G[2010][2010];
ll D[2010];
void Dijkstra(int src){
fill(&D[0], &D[0]+2010, INF);
D[src]=0LL;
priority_queue<pli, vector<pli>, greater<pli>> Q;
Q.push({0LL, src});
while(! Q.empty()){
auto [dist, cur] = Q.top();
Q.pop();
if (dist>D[cur]) continue;
for (int dst=0;dst<2*N+2;dst++){
if (dist+G[cur][dst]<D[dst]){
D[dst]=dist+G[cur][dst];
Q.push({D[dst], dst});
}
}
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll H, W;
cin>>H>>W>>N;
pos[0]={1LL, 1LL}, pos[1]={H, W};
for (int i=1;i<=N;i++){
cin>>pos[2*i].x>>pos[2*i].y>>pos[2*i+1].x>>pos[2*i+1].y;
}
for (int i=0;i<2*N+2;i++){
for (int j=i;j<2*N+2;j++){
G[i][j]=pos[i].distance(pos[j]);
G[j][i]=G[i][j];
}
}
for (int i=1;i<=N;i++) G[2*i][2*i+1]=1;
Dijkstra(0);
cout << D[1] << "\n";
return 0;
}