結果
| 問題 |
No.2695 Warp Zone
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-03-28 15:11:13 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 37 ms / 2,000 ms |
| コード長 | 1,306 bytes |
| コンパイル時間 | 4,612 ms |
| コンパイル使用メモリ | 313,944 KB |
| 実行使用メモリ | 35,000 KB |
| 最終ジャッジ日時 | 2024-09-30 14:44:54 |
| 合計ジャッジ時間 | 5,741 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 24 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
#include<atcoder/all>
using namespace atcoder;
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ld = long double;
using ll = long long;
template<class T> bool chmax(T &a, T b)
{
if(a<b)
{
a = b;
return true;
}
return false;
}
template<class T> bool chmin(T &a, T b)
{
if(a>b)
{
a = b;
return true;
}
return false;
}
int H, W, N, A[1<<10][4];
using P = pair<ll,ll>;
int main()
{
cin >> H >> W >> N;
rep(i,N) rep(j,4) cin >> A[i][j];
int M = 2*N+2;
ll G[M][M] = {};
rep(i,M) rep(j,M) G[i][j] = 1e18;
rep(i,2*N) rep(j,2*N) if(i!=j)
{
int a = (i&1?2:0);
int b = (j&1?2:0);
G[i][j] = abs(A[i/2][a]-A[j/2][b]) + abs(A[i/2][a+1]-A[j/2][b+1]);
}
rep(i,N) G[2*i][2*i+1] = 1;
rep(i,2*N)
{
int a = (i&1?2:0);
G[2*N][i] = G[i][2*N] = A[i/2][a] + A[i/2][a+1] - 2;
G[2*N+1][i] = G[i][2*N+1] = H-A[i/2][a] + W-A[i/2][a+1];
}
G[2*N][2*N+1] = H+W-2;
priority_queue<P, vector<P>, greater<P>> q;
q.push({0,2*N});
vector<ll> dist(2*N+2, 1e18);
dist[2*N] = 0;
while(!q.empty())
{
auto [c,v] = q.top();
q.pop();
if(dist[v]<c) continue;
rep(nv,2*N+2) if(nv!=v && G[v][nv]<1e18)
{
if(chmin(dist[nv], dist[v]+G[v][nv])) q.push({dist[nv], nv});
}
}
//rep(i,M) cout << dist[i] << endl;
cout << dist[2*N+1] << endl;
}