結果
問題 | No.2695 Warp Zone |
ユーザー | hirakuuuu |
提出日時 | 2024-03-22 22:13:07 |
言語 | C++23 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 83 ms / 2,000 ms |
コード長 | 2,305 bytes |
コンパイル時間 | 2,782 ms |
コンパイル使用メモリ | 263,376 KB |
実行使用メモリ | 68,352 KB |
最終ジャッジ日時 | 2024-09-30 11:41:58 |
合計ジャッジ時間 | 4,383 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,248 KB |
testcase_02 | AC | 2 ms
5,248 KB |
testcase_03 | AC | 83 ms
68,352 KB |
testcase_04 | AC | 78 ms
67,072 KB |
testcase_05 | AC | 79 ms
67,072 KB |
testcase_06 | AC | 80 ms
68,096 KB |
testcase_07 | AC | 83 ms
68,352 KB |
testcase_08 | AC | 2 ms
5,248 KB |
testcase_09 | AC | 33 ms
32,768 KB |
testcase_10 | AC | 2 ms
5,248 KB |
testcase_11 | AC | 10 ms
12,416 KB |
testcase_12 | AC | 42 ms
41,984 KB |
testcase_13 | AC | 2 ms
5,248 KB |
testcase_14 | AC | 52 ms
50,304 KB |
testcase_15 | AC | 28 ms
29,184 KB |
testcase_16 | AC | 9 ms
10,752 KB |
testcase_17 | AC | 14 ms
16,512 KB |
testcase_18 | AC | 64 ms
59,136 KB |
testcase_19 | AC | 2 ms
5,248 KB |
testcase_20 | AC | 58 ms
53,632 KB |
testcase_21 | AC | 53 ms
49,408 KB |
testcase_22 | AC | 19 ms
19,584 KB |
testcase_23 | AC | 41 ms
41,856 KB |
testcase_24 | AC | 2 ms
5,248 KB |
testcase_25 | AC | 2 ms
5,248 KB |
testcase_26 | AC | 2 ms
5,248 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; #define rep(i, a, n) for(int i = a; i < n; i++) #define rrep(i, a, n) for(int i = a; i >= n; i--) #define ll long long #define pii pair<int, int> #define pll pair<ll, ll> // constexpr ll MOD = 1000000007; constexpr ll MOD = 998244353; constexpr int IINF = 1001001001; constexpr ll INF = 1LL<<60; template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;} template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;} vector<ll> dijk(ll s, vector<vector<pll>> &g){ priority_queue<pll, vector<pll>, greater<pll>> que; vector<ll> dist(g.size(), (1LL<<60)); que.push(make_pair(0, s)); dist[s] = 0; while(!que.empty()){ pll q = que.top(); que.pop(); ll d = q.first, u = q.second; if(dist[u] < d) continue; for(auto nq: g[u]){ ll v = nq.first, cost = nq.second; if(dist[v] > d+cost){ dist[v] = d+cost; que.push({dist[v], v}); } } } return dist; } int main(){ int h, w, n; cin >> h >> w >> n; vector<vector<pair<ll, ll>>> g(2*n+2); vector<ll> a(n), b(n), c(n), d(n); rep(i, 0, n) cin >> a[i] >> b[i] >> c[i] >> d[i]; rep(i, 0, n){ g[2*i].push_back({2*i+1, 1}); g[2*i+1].push_back({2*i, abs(a[i]-c[i])+abs(b[i]-d[i])}); } rep(i, 0, n){ rep(j, i+1, n){ g[2*i].push_back({2*j, abs(a[i]-a[j])+abs(b[i]-b[j])}); g[2*j].push_back({2*i, abs(a[i]-a[j])+abs(b[i]-b[j])}); g[2*i].push_back({2*j+1, abs(a[i]-c[j])+abs(b[i]-d[j])}); g[2*j+1].push_back({2*i, abs(a[i]-c[j])+abs(b[i]-d[j])}); g[2*i+1].push_back({2*j, abs(c[i]-a[j])+abs(d[i]-b[j])}); g[2*j].push_back({2*i+1, abs(c[i]-a[j])+abs(d[i]-b[j])}); g[2*i+1].push_back({2*j+1, abs(c[i]-c[j])+abs(d[i]-d[j])}); g[2*j+1].push_back({2*i+1, abs(c[i]-c[j])+abs(d[i]-d[j])}); } } rep(i, 0, n){ g[2*n].push_back({2*i, a[i]-1+b[i]-1}); g[2*i].push_back({2*n+1, h-a[i]+w-b[i]}); g[2*i+1].push_back({2*n+1, h-c[i]+w-d[i]}); } g[2*n].push_back({2*n+1, h-1+w-1}); vector<ll> dist = dijk(2*n, g); cout << dist[2*n+1] << endl; return 0; }