結果
| 問題 |
No.2695 Warp Zone
|
| コンテスト | |
| ユーザー |
shobonvip
|
| 提出日時 | 2024-03-23 04:11:29 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 47 ms / 2,000 ms |
| コード長 | 2,390 bytes |
| コンパイル時間 | 4,981 ms |
| コンパイル使用メモリ | 273,616 KB |
| 最終ジャッジ日時 | 2025-02-20 13:01:36 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 24 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
//* ATCODER
#include<atcoder/all>
using namespace atcoder;
typedef modint998244353 mint;
//*/
/* BOOST MULTIPRECISION
#include<boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
//*/
typedef long long ll;
#define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--)
template <typename T> bool chmin(T &a, const T &b) {
if (a <= b) return false;
a = b;
return true;
}
template <typename T> bool chmax(T &a, const T &b) {
if (a >= b) return false;
a = b;
return true;
}
template <typename T> T max(vector<T> &a){
assert(!a.empty());
T ret = a[0];
for (int i=0; i<(int)a.size(); i++) chmax(ret, a[i]);
return ret;
}
template <typename T> T min(vector<T> &a){
assert(!a.empty());
T ret = a[0];
for (int i=0; i<(int)a.size(); i++) chmin(ret, a[i]);
return ret;
}
template <typename T> T sum(vector<T> &a){
T ret = 0;
for (int i=0; i<(int)a.size(); i++) ret += a[i];
return ret;
}
// defcomp
template <typename T>
vector<T> compress(vector<T> &X) {
vector<T> vals = X;
sort(vals.begin(), vals.end());
vals.erase(unique(vals.begin(), vals.end()), vals.end());
return vals;
}
// -----
int main(){
ll h, w, n; cin >> h >> w >> n;
vector<pair<ll,ll>> points;
vector<ll> a(n),b(n),c(n),dd(n);
rep(i,0,n){
cin >> a[i] >> b[i] >> c[i] >> dd[i];
points.push_back(pair(a[i], b[i]));
points.push_back(pair(c[i], dd[i]));
}
points.push_back(pair(1, 1));
points.push_back(pair(h, w));
points = compress(points);
map<pair<ll,ll>,int> taio;
int m = points.size();
rep(i,0,m){
taio[points[i]] = i;
}
vector dist(m, vector<ll>(m,1e18));
rep(i,0,n){
int x = taio[pair(a[i], b[i])];
int y = taio[pair(c[i], dd[i])];
chmin(dist[x][y], 1LL);
}
rep(i,0,m){
rep(j,0,m){
ll x1 = points[i].first;
ll x2 = points[j].first;
ll y1 = points[i].second;
ll y2 = points[j].second;
chmin(dist[i][j], abs(x1-x2) + abs(y1-y2));
}
}
vector<ll> d(m,(ll)1e18);
priority_queue<pair<ll,int>> pq;
d[taio[pair(1,1)]] = 0;
pq.push(pair(0, taio[pair(1,1)]));
while(!pq.empty()){
auto [tmp, i] = pq.top();
pq.pop();
tmp = -tmp;
if (tmp > d[i]) continue;
rep(j,0,m){
ll targ = tmp + dist[i][j];
if (chmin(d[j], targ)){
pq.push(pair(-d[j],j));
}
}
}
cout << d[taio[pair(h,w)]] << '\n';
}
shobonvip