結果
問題 | No.2695 Warp Zone |
ユーザー |
![]() |
提出日時 | 2024-03-22 22:08:57 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 22 ms / 2,000 ms |
コード長 | 1,083 bytes |
コンパイル時間 | 2,684 ms |
コンパイル使用メモリ | 244,272 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-09-30 11:37:55 |
合計ジャッジ時間 | 3,675 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 24 |
ソースコード
#include <bits/stdc++.h>using namespace std;using ll = long long;const int inf = (int)2e9 + 1;int H, W, N;int X[2020], Y[2020];int dist[2020], used[2020];int main(void){ios::sync_with_stdio(false);cin.tie(nullptr);cin >> H >> W >> N;int cnt = 1;X[0] = 1, Y[0] = 1;for(int i = 0;i < N;i++){int a, b, c, d; cin >> a >> b >> c >> d;X[cnt] = a, Y[cnt] = b;cnt++;X[cnt] = c, Y[cnt] = d;cnt++;}X[cnt] = H, Y[cnt] = W; cnt++;for(int i = 1;i < cnt;i++)dist[i] = inf;while(1){int v = -1, d = inf;for(int i = 0;i < cnt;i++)if(!used[i]){if(d > dist[i])v = i, d = dist[i];}used[v] = 1;if(v == -1)break;for(int nv = 0;nv < cnt;nv++){ll tmp = d + abs(X[v] - X[nv]) + abs(Y[v] - Y[nv]);if(v % 2 == 1 && nv == v + 1)tmp = d + 1;if(tmp > inf)continue;int nd = tmp;dist[nv] = min(dist[nv], nd);}}cout << dist[cnt - 1] << endl;return 0;}