結果

問題 No.323 yuki国
ユーザー pekempeypekempey
提出日時 2015-12-16 00:09:05
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 413 ms / 5,000 ms
コード長 1,554 bytes
コンパイル時間 1,298 ms
コンパイル使用メモリ 154,344 KB
実行使用メモリ 52,464 KB
最終ジャッジ日時 2023-09-10 21:12:25
合計ジャッジ時間 8,185 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
52,316 KB
testcase_01 AC 19 ms
52,224 KB
testcase_02 AC 19 ms
52,144 KB
testcase_03 AC 26 ms
52,232 KB
testcase_04 AC 19 ms
52,148 KB
testcase_05 AC 20 ms
52,168 KB
testcase_06 AC 20 ms
52,164 KB
testcase_07 AC 19 ms
52,324 KB
testcase_08 AC 267 ms
52,224 KB
testcase_09 AC 264 ms
52,188 KB
testcase_10 AC 20 ms
52,156 KB
testcase_11 AC 19 ms
52,256 KB
testcase_12 AC 20 ms
52,252 KB
testcase_13 AC 250 ms
52,304 KB
testcase_14 AC 267 ms
52,188 KB
testcase_15 AC 73 ms
52,400 KB
testcase_16 AC 267 ms
52,260 KB
testcase_17 AC 315 ms
52,184 KB
testcase_18 AC 97 ms
52,292 KB
testcase_19 AC 199 ms
52,180 KB
testcase_20 AC 413 ms
52,248 KB
testcase_21 AC 405 ms
52,372 KB
testcase_22 AC 404 ms
52,364 KB
testcase_23 AC 390 ms
52,200 KB
testcase_24 AC 90 ms
52,256 KB
testcase_25 AC 84 ms
52,272 KB
testcase_26 AC 328 ms
52,464 KB
testcase_27 AC 359 ms
52,216 KB
testcase_28 AC 309 ms
52,212 KB
testcase_29 AC 307 ms
52,340 KB
testcase_30 AC 20 ms
52,144 KB
testcase_31 AC 19 ms
52,168 KB
testcase_32 AC 20 ms
52,308 KB
testcase_33 AC 20 ms
52,384 KB
testcase_34 AC 20 ms
52,148 KB
testcase_35 AC 20 ms
52,280 KB
testcase_36 AC 20 ms
52,180 KB
testcase_37 AC 20 ms
52,196 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define GET_MACRO(a, b, c, NAME, ...) NAME
#define rep(...) GET_MACRO(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define rep2(i, a) rep3 (i, 0, a)
#define rep3(i, a, b) for (int i = (a); i < (b); i++)
#define repr(...) GET_MACRO(__VA_ARGS__, repr3, repr2)(__VA_ARGS__)
#define repr2(i, a) repr3 (i, 0, a)
#define repr3(i, a, b) for (int i = (b) - 1; i >= (a); i--)
template<class T1, class T2> inline bool chmin(T1 &a, T2 b) { return b < a && (a = b, true); }
template<class T1, class T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
using namespace std;
typedef long long ll;

string g[50];
const int inf = 1e9;
int dist[50][50][5000];
int dy[] = {0, 1, 0, -1};
int dx[] = {1, 0, -1, 0};

int main() {
	int h, w;
	cin >> h >> w;
	int a, sy, sx;
	cin >> a >> sy >> sx;
	int b, gy, gx;
	cin >> b >> gy >> gx;
	rep (i, h) cin >> g[i];

	queue<tuple<int, int, int>> q;
	rep (i, 50) rep (j, 50) rep (k, 5000) dist[i][j][k] = inf;
	dist[sy][sx][a] = 0;
	q.emplace(sy, sx, a);
	while (!q.empty()) {
		int y, x, s;
		tie(y, x, s) = q.front(); q.pop();
		rep (k, 4) {
			int ny = y + dy[k];
			int nx = x + dx[k];
			if (ny < 0 || nx < 0 || ny >= h || nx >= w) continue;
			int delta;
			if (g[ny][nx] == '*') delta = 1;
			else delta = -1;
			if (s + delta == 0) continue;
			if (s + delta >= 5000) continue;
			if (chmin(dist[ny][nx][s + delta], dist[y][x][s] + 1)) {
				q.emplace(ny, nx, s + delta);
			}
		}
	}
	if (dist[gy][gx][b] < inf) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
	return 0;
}
0