結果
| 問題 | No.3679 なんかでっかい虫リターンズ |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-09-05 13:18:58 |
| 言語 | C++23(gcc16) (gcc 16.1.0 + boost 1.92.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| + 135µs | |
| コード長 | 975 bytes |
| 記録 | |
| コンパイル時間 | 2,379 ms |
| コンパイル使用メモリ | 362,048 KB |
| 実行使用メモリ | 9,784 KB |
| 最終ジャッジ日時 | 2026-09-05 13:19:03 |
| 合計ジャッジ時間 | 3,909 ms |
|
ジャッジサーバーID (参考情報) |
judge4_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 17 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (n); i++)
const vector<ll> di = {1, 0, -1, 0};
const vector<ll> dj = {0, 1, 0, -1};
int main() {
ll h, w, a, b, r1, c1, r2, c2, p, q;
cin >> h >> w >> a >> b >> r1 >> c1 >> r2 >> c2 >> p >> q;
a--; b--; r1--; c1--; p--; q--;
vector dist(h, vector<ll>(w, -1));
queue<pair<ll, ll>> que;
dist[a][b] = 0;
que.emplace(a, b);
while (!que.empty()) {
auto [i, j] = que.front(); que.pop();
rep(p, 4) {
ll ni = i + di[p], nj = j + dj[p];
if (ni < 0 || ni >= h || nj < 0 || nj >= w || dist[ni][nj] != -1) continue;
dist[ni][nj] = dist[i][j] + 1;
que.emplace(ni, nj);
}
}
ll ans = 1e18;
rep(i, h)rep(j, w) if (r1 <= i && i < r2 && c1 <= j && j < c2) ans = min(ans, dist[i][j] + abs(i-p) + abs(j-q) + abs(a-p) + abs(b-q));
cout << ans << endl;
return 0;
}