結果
問題 | No.2695 Warp Zone |
ユーザー | 👑 binap |
提出日時 | 2024-03-22 21:58:27 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 1,649 ms / 2,000 ms |
コード長 | 3,512 bytes |
コンパイル時間 | 4,076 ms |
コンパイル使用メモリ | 281,412 KB |
実行使用メモリ | 204,712 KB |
最終ジャッジ日時 | 2024-09-30 11:30:50 |
合計ジャッジ時間 | 19,763 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 2 ms
5,248 KB |
testcase_03 | AC | 1,541 ms
203,432 KB |
testcase_04 | AC | 1,622 ms
200,852 KB |
testcase_05 | AC | 1,599 ms
200,008 KB |
testcase_06 | AC | 1,630 ms
202,456 KB |
testcase_07 | AC | 1,649 ms
204,712 KB |
testcase_08 | AC | 5 ms
5,248 KB |
testcase_09 | AC | 468 ms
89,752 KB |
testcase_10 | AC | 2 ms
5,248 KB |
testcase_11 | AC | 113 ms
27,308 KB |
testcase_12 | AC | 703 ms
114,568 KB |
testcase_13 | AC | 2 ms
5,248 KB |
testcase_14 | AC | 804 ms
158,956 KB |
testcase_15 | AC | 370 ms
82,024 KB |
testcase_16 | AC | 95 ms
23,412 KB |
testcase_17 | AC | 221 ms
44,596 KB |
testcase_18 | AC | 1,224 ms
176,020 KB |
testcase_19 | AC | 3 ms
5,248 KB |
testcase_20 | AC | 1,005 ms
166,140 KB |
testcase_21 | AC | 873 ms
157,612 KB |
testcase_22 | AC | 297 ms
58,184 KB |
testcase_23 | AC | 614 ms
112,012 KB |
testcase_24 | AC | 2 ms
5,248 KB |
testcase_25 | AC | 1 ms
5,248 KB |
testcase_26 | AC | 2 ms
5,248 KB |
ソースコード
#include<bits/stdc++.h> #include<atcoder/all> #define rep(i,n) for(int i=0;i<n;i++) using namespace std; using namespace atcoder; typedef long long ll; typedef vector<int> vi; typedef vector<long long> vl; typedef vector<vector<int>> vvi; typedef vector<vector<long long>> vvl; typedef long double ld; typedef pair<int, int> P; ostream& operator<<(ostream& os, const modint& a) {os << a.val(); return os;} template <int m> ostream& operator<<(ostream& os, const static_modint<m>& a) {os << a.val(); return os;} template <int m> ostream& operator<<(ostream& os, const dynamic_modint<m>& a) {os << a.val(); return os;} template<typename T> istream& operator>>(istream& is, vector<T>& v){int n = v.size(); assert(n > 0); rep(i, n) is >> v[i]; return is;} template<typename U, typename T> ostream& operator<<(ostream& os, const pair<U, T>& p){os << p.first << ' ' << p.second; return os;} template<typename T> ostream& operator<<(ostream& os, const vector<T>& v){int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "\n" : " "); return os;} template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v){int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "\n" : ""); return os;} template<typename T> void chmin(T& a, T b){a = min(a, b);} template<typename T> void chmax(T& a, T b){a = max(a, b);} template<typename T> struct Edge_Dijkstra{ int from, to; T cost; Edge_Dijkstra(int from, int to, T cost) : from(from), to(to), cost(cost) {}; }; const int INF = 1001001001; template<typename T> struct Dijkstra{ int n, m; vector<bool> initialized; vector<Edge_Dijkstra<T>> E; vector<vector<int>> G; map<int, vector<T>> dist; map<int, vector<int>> idx; Dijkstra(int _n) : n(_n), m(0), initialized(n, false), G(n){} void add_edge(int from, int to, T cost){ Edge_Dijkstra e(from, to, cost); E.push_back(e); G[from].emplace_back(m); m++; } void calc(int s){ initialized[s] = true; dist[s] = vector<T>(n, INF); idx[s] = vector<int>(n, -1); priority_queue<tuple<T, int, int>, vector<tuple<T, int, int>>, greater<tuple<T, int, int>>> pq; pq.emplace(0, s, -1); while(pq.size()){ auto [cost, from, index] = pq.top(); pq.pop(); if(dist[s][from] <= cost) continue; dist[s][from] = cost; idx[s][from] = index; for(int index : G[from]){ int to = E[index].to; T cost_plus = E[index].cost; if(dist[s][to] <= cost + cost_plus) continue; pq.emplace(cost + cost_plus, to, index); } } } int farthest(int s){ if(!initialized[s]) calc(s); int idx = 0; rep(i, n) if(dist[s][i] > dist[s][idx]) idx = i; return idx; } T get_dist(int s, int t){ if(!initialized[s]) calc(s); return dist[s][t]; } vi restore(int s, int t){ if(!initialized[s]) calc(s); if(dist[s][t] == INF) return vi(0); vi res; while(idx[s][t] != -1){ auto e = E[idx[s][t]]; res.push_back(idx[s][t]); t = e.from; } reverse(res.begin(), res.end()); return res; } }; int main(){ int h, w, n; cin >> h >> w >> n; int m = 2 * n + 2; vector<long long> y(2 * n + 2), x(2 * n + 2); int sv = 2 * n; int tv = 2 * n + 1; rep(i, n){ cin >> y[2 * i] >> x[2 * i]; cin >> y[2 * i + 1] >> x[2 * i + 1]; } y[sv] = 1; x[sv] = 1; y[tv] = h; x[tv] = w; Dijkstra<int> graph(m); rep(i, m){ rep(j, m){ graph.add_edge(i, j, abs(x[i] - x[j]) + abs(y[i] - y[j])); graph.add_edge(j, i, abs(x[i] - x[j]) + abs(y[i] - y[j])); } } rep(i, n){ graph.add_edge(2 * i, 2 * i + 1, 1LL); } cout << graph.get_dist(sv, tv) << "\n"; return 0; }