結果

問題 No.323 yuki国
ユーザー antaanta
提出日時 2015-12-16 00:10:14
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 391 ms / 5,000 ms
コード長 2,193 bytes
コンパイル時間 732 ms
コンパイル使用メモリ 82,812 KB
実行使用メモリ 22,032 KB
最終ジャッジ日時 2023-09-10 21:12:36
合計ジャッジ時間 5,272 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 279 ms
4,988 KB
testcase_09 AC 51 ms
4,956 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 51 ms
5,056 KB
testcase_14 AC 291 ms
5,248 KB
testcase_15 AC 51 ms
5,004 KB
testcase_16 AC 286 ms
5,380 KB
testcase_17 AC 51 ms
7,084 KB
testcase_18 AC 17 ms
4,412 KB
testcase_19 AC 151 ms
8,636 KB
testcase_20 AC 7 ms
5,332 KB
testcase_21 AC 391 ms
21,436 KB
testcase_22 AC 10 ms
5,916 KB
testcase_23 AC 386 ms
22,032 KB
testcase_24 AC 65 ms
5,076 KB
testcase_25 AC 64 ms
5,056 KB
testcase_26 AC 306 ms
4,964 KB
testcase_27 AC 311 ms
4,936 KB
testcase_28 AC 61 ms
5,020 KB
testcase_29 AC 63 ms
4,960 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 1 ms
4,376 KB
testcase_34 AC 2 ms
4,376 KB
testcase_35 AC 2 ms
4,376 KB
testcase_36 AC 1 ms
4,380 KB
testcase_37 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
using namespace std;
typedef vector<int> vi; typedef pair<int,int> pii; typedef vector<pair<int,int> > vpii; typedef long long ll;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }

int main() {
	int H; int W;
	while(~scanf("%d%d", &H, &W)) {
		int A; int Si; int Sj;
		scanf("%d%d%d", &A, &Si, &Sj);
		int B; int Gi; int Gj;
		scanf("%d%d%d", &B, &Gi, &Gj);
		vector<string> M(H);
		rep(i, H) cin >> M[i];
		const int MaxX = max(A, B) + H * W * 2;
		vector<bool> vis((MaxX+1) * H * W);
		int inits = (A * H + Si) * W + Sj;
		vi stk;
		vis[inits] = true;
		stk.push_back(inits);
		bool ans = false;
		while(!stk.empty()) {
			int s = stk.back(); stk.pop_back();
			int i = s / W % H, j = s % W, x = s / (H * W);
			if(x == B && i == Gi && j == Gj) {
				ans = true;
				break;
			}
			static const int dy[4] = {0, 1, 0, -1}, dx[4] = {1, 0, -1, 0};
			rep(d, 4) {
				int yy = i + dy[d], xx = j + dx[d];
				if(yy < 0 || yy >= H || xx < 0 || xx >= W) continue;
				int nx = x + (M[yy][xx] == '*' ? 1 : -1);
				if(nx <= 0 || nx > MaxX) continue;
				int ns = (nx * H + yy) * W + xx;
				if(vis[ns]) continue;
				vis[ns] = true;
				stk.push_back(ns);
			}
		}
		puts(ans ? "Yes" : "No");
	}
	return 0;
}
0