結果
| 問題 |
No.8063 幅優先探索
|
| コンテスト | |
| ユーザー |
FSM
|
| 提出日時 | 2020-04-01 21:36:11 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,463 bytes |
| コンパイル時間 | 1,900 ms |
| コンパイル使用メモリ | 183,880 KB |
| 実行使用メモリ | 7,552 KB |
| 最終ジャッジ日時 | 2024-06-27 09:37:43 |
| 合計ジャッジ時間 | 3,391 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 3 WA * 1 RE * 5 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define rep2(i, s, n) for (int i = s; i < (int)n; i++)
#define rep3(i, s, n) for (int i = s; i > (int)n; i--)
#define all(obj) obj.begin(), obj.end()
#define db(x) cerr << #x << ":" << x << " "
#define dbl(x) cerr << #x << ":" << x << "\n"
#define dbv(vec) cerr << #vec << ":"; for (auto e : vec) cerr << e << " "; cout << "\n"
#define dbvv(vv) cerr << #vv << ":\n"; for (auto vec : vv) { for (auto e : vec) cerr << e << " "; cout << endl; }
#define YN(f) cout << (f ? "YES" : "NO") << endl
#define Yn(f) cout << (f ? "Yes" : "No") << endl
#define yn(f) cout << (f ? "yes" : "no") << endl
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
int main () {
int R, C; cin >> R >> C;
int sy, sx; cin >> sy >> sx;
int gy, gx; cin >> gy >> gx;
vector<vector<bool>> g(R + 1, vector<bool>(C + 1));
rep2(i, 1, R + 1) {
string c; cin >> c;
rep2(j, 1, C + 1) g[i][j] = c[j - 1] == '.';
}
vvi d(R, vi(C, -1));
queue<pii> q;
pii s(sy, sx);
q.push(s); d[sy][sx] = 0;
while (!q.empty()) {
pii u = q.front(); q.pop();
int i, j; tie(i, j) = u;
vi di = { 1, 0, -1, 0 }, dj = { 0, 1, 0, -1 };
rep(k, 4) {
int ni = i + di[k], nj = j + dj[k];
if (!g[ni][nj] or d[ni][nj] != -1) continue;
d[ni][nj] = d[i][j] + 1;
pii v(ni, nj);
q.push(v);
}
}
// dbvv(g);
// dbvv(d);
cout << d[gy][gx] << endl;
}
FSM