結果
問題 | No.2695 Warp Zone |
ユーザー | hirakuuuu |
提出日時 | 2024-03-22 22:11:16 |
言語 | C++23 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,301 bytes |
コンパイル時間 | 3,391 ms |
コンパイル使用メモリ | 261,748 KB |
実行使用メモリ | 68,352 KB |
最終ジャッジ日時 | 2024-09-30 11:40:05 |
合計ジャッジ時間 | 5,302 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 2 ms
5,248 KB |
testcase_03 | AC | 99 ms
68,352 KB |
testcase_04 | AC | 96 ms
67,072 KB |
testcase_05 | AC | 96 ms
67,072 KB |
testcase_06 | AC | 99 ms
67,968 KB |
testcase_07 | AC | 100 ms
68,352 KB |
testcase_08 | AC | 3 ms
5,248 KB |
testcase_09 | AC | 39 ms
32,768 KB |
testcase_10 | AC | 2 ms
5,248 KB |
testcase_11 | AC | 12 ms
12,288 KB |
testcase_12 | AC | 52 ms
41,856 KB |
testcase_13 | AC | 2 ms
5,248 KB |
testcase_14 | AC | 67 ms
50,304 KB |
testcase_15 | AC | 35 ms
29,312 KB |
testcase_16 | AC | 11 ms
10,752 KB |
testcase_17 | AC | 19 ms
16,512 KB |
testcase_18 | AC | 81 ms
59,264 KB |
testcase_19 | AC | 2 ms
5,248 KB |
testcase_20 | AC | 72 ms
53,632 KB |
testcase_21 | AC | 65 ms
49,408 KB |
testcase_22 | AC | 25 ms
19,584 KB |
testcase_23 | AC | 53 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+w}); vector<ll> dist = dijk(2*n, g); cout << dist[2*n+1] << endl; return 0; }