結果
問題 | No.2695 Warp Zone |
ユーザー |
![]() |
提出日時 | 2024-03-23 04:51:11 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 43 ms / 2,000 ms |
コード長 | 1,479 bytes |
コンパイル時間 | 2,353 ms |
コンパイル使用メモリ | 212,928 KB |
実行使用メモリ | 34,688 KB |
最終ジャッジ日時 | 2024-09-30 13:03:43 |
合計ジャッジ時間 | 3,426 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 24 |
ソースコード
#include <bits/stdc++.h>using namespace std;void fast_io() {ios::sync_with_stdio(false);std::cin.tie(nullptr);}int main() {fast_io();int n;long long h, w;cin >> h >> w >> n;vector<pair<long long, long long>> points{{1, 1}, {h, w}};vector<vector<long long>> dist(2 * n + 2, vector<long long>(2 * n + 2, 0));for (int i = 0; i < n; i++) {long long a, b, c, d;cin >> a >> b >> c >> d;points.push_back({a, b});points.push_back({c, d});dist[2 * i + 2][2 * i + 3] = 1;}for (int i = 0; i < 2 * n + 2; i++) {for (int j = 0; j < 2 * n + 2; j++) {if (dist[i][j]) {continue;}dist[i][j] = abs(points[i].first - points[j].first) +abs(points[i].second - points[j].second);}}const long long INF = 1e18;vector<bool> vis(2 * n + 2, false);vector<long long> ans(2 * n + 2, INF);ans[0] = 0;for (int i = 0; i < 2 * n + 2; i++) {int v = -1;long long ma = INF;for (int j = 0; j < 2 * n + 2; j++) {if (!vis[j] && ans[j] < ma) {ma = ans[j];v = j;}}if (v == -1) {break;}vis[v] = true;for (int u = 0; u < 2 * n + 2; u++) {ans[u] = min(ans[u], ans[v] + dist[v][u]);}}cout << ans[1] << endl;}