結果
問題 | No.2695 Warp Zone |
ユーザー | shobonvip |
提出日時 | 2024-03-23 04:11:29 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 42 ms / 2,000 ms |
コード長 | 2,390 bytes |
コンパイル時間 | 4,666 ms |
コンパイル使用メモリ | 284,992 KB |
実行使用メモリ | 35,456 KB |
最終ジャッジ日時 | 2024-09-30 13:02:39 |
合計ジャッジ時間 | 5,261 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,820 KB |
testcase_01 | AC | 1 ms
6,816 KB |
testcase_02 | AC | 1 ms
6,820 KB |
testcase_03 | AC | 42 ms
35,200 KB |
testcase_04 | AC | 38 ms
34,136 KB |
testcase_05 | AC | 38 ms
34,048 KB |
testcase_06 | AC | 40 ms
35,072 KB |
testcase_07 | AC | 39 ms
35,456 KB |
testcase_08 | AC | 2 ms
6,816 KB |
testcase_09 | AC | 13 ms
13,952 KB |
testcase_10 | AC | 2 ms
6,816 KB |
testcase_11 | AC | 5 ms
6,820 KB |
testcase_12 | AC | 20 ms
18,304 KB |
testcase_13 | AC | 2 ms
6,820 KB |
testcase_14 | AC | 24 ms
23,040 KB |
testcase_15 | AC | 11 ms
12,544 KB |
testcase_16 | AC | 4 ms
6,816 KB |
testcase_17 | AC | 7 ms
8,704 KB |
testcase_18 | AC | 32 ms
27,560 KB |
testcase_19 | AC | 2 ms
6,816 KB |
testcase_20 | AC | 28 ms
24,832 KB |
testcase_21 | AC | 24 ms
22,528 KB |
testcase_22 | AC | 10 ms
11,648 KB |
testcase_23 | AC | 18 ms
18,176 KB |
testcase_24 | AC | 2 ms
6,816 KB |
testcase_25 | AC | 1 ms
6,816 KB |
testcase_26 | AC | 2 ms
6,816 KB |
ソースコード
#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'; }