結果

問題 No.323 yuki国
ユーザー Yang33Yang33
提出日時 2018-10-02 23:56:39
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 117 ms / 5,000 ms
コード長 2,086 bytes
コンパイル時間 1,847 ms
コンパイル使用メモリ 173,456 KB
実行使用メモリ 8,704 KB
最終ジャッジ日時 2024-04-20 14:33:49
合計ジャッジ時間 3,846 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 7 ms
8,448 KB
testcase_06 AC 8 ms
8,576 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 71 ms
8,448 KB
testcase_09 AC 40 ms
6,528 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 5 ms
6,144 KB
testcase_12 AC 4 ms
6,144 KB
testcase_13 AC 39 ms
6,272 KB
testcase_14 AC 73 ms
8,704 KB
testcase_15 AC 36 ms
5,888 KB
testcase_16 AC 71 ms
8,544 KB
testcase_17 AC 48 ms
6,144 KB
testcase_18 AC 3 ms
5,376 KB
testcase_19 AC 58 ms
8,544 KB
testcase_20 AC 4 ms
5,376 KB
testcase_21 AC 116 ms
8,576 KB
testcase_22 AC 19 ms
5,376 KB
testcase_23 AC 117 ms
8,704 KB
testcase_24 AC 6 ms
5,376 KB
testcase_25 AC 46 ms
6,144 KB
testcase_26 AC 6 ms
5,376 KB
testcase_27 AC 97 ms
8,448 KB
testcase_28 AC 53 ms
6,272 KB
testcase_29 AC 47 ms
6,400 KB
testcase_30 AC 2 ms
5,376 KB
testcase_31 AC 7 ms
8,704 KB
testcase_32 AC 7 ms
8,448 KB
testcase_33 AC 7 ms
8,576 KB
testcase_34 AC 8 ms
8,448 KB
testcase_35 AC 2 ms
5,376 KB
testcase_36 AC 8 ms
8,576 KB
testcase_37 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2018/10/02  Problem: yukicoder 323  / Link: http://yukicoder.me/problems/no/323  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

LL ans = 0LL;
bool d[3003][51][51];

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);

	int H, W; cin >> H >> W;
	int A; PII s; cin >> A >> s.first >> s.second;
	int B; PII t; cin >> B >> t.first >> t.second;
	VS vs(H);
	FOR(i, 0, H) {
		cin >> vs[i];
	}

	const int Max = 2000;
	auto f = [&]() {

		using tp = tuple<int, int, int>;
		queue<tp>q;
		d[A][s.first][s.second] = 1;
		q.push(tp(A, s.first, s.second));
		while (!q.empty()) {
			int dist, y, x;
			tie(dist, y, x) = q.front(); q.pop();

#define IN(a,b,c) (a<=b&&b<c)
			FOR(k, 0, 4) {
				int ny = y + DY[k], nx = x + DX[k];
				if (IN(0, ny, H) && IN(0, nx, W)) {
					int c = (vs[ny][nx] == '*' ? 1 : -1);
					int nd = dist + c;
					if (nd > Max || nd <= 0)continue;
					if (!d[nd][ny][nx]) {
						d[nd][ny][nx] = 1;
						q.push(tp(nd, ny, nx));
						if (nd == B && PII(ny, nx) == t) { return 1; }
					}
				}
			}

		}
		return 0;
	};
	ans = f();
	cout << (ans ? "Yes" : "No") << "\n";

	return 0;
}
0