結果

問題 No.3063 幅優先探索
ユーザー FSMFSM
提出日時 2020-04-01 21:35:11
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,463 bytes
コンパイル時間 1,835 ms
コンパイル使用メモリ 181,228 KB
実行使用メモリ 7,492 KB
最終ジャッジ日時 2023-09-09 16:46:21
合計ジャッジ時間 3,893 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 AC 2 ms
4,380 KB
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 WA -
testcase_06 RE -
testcase_07 AC 84 ms
7,492 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0