結果

問題 No.323 yuki国
ユーザー かにかに
提出日時 2015-12-17 17:33:58
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 539 ms / 5,000 ms
コード長 1,574 bytes
コンパイル時間 1,245 ms
コンパイル使用メモリ 152,512 KB
実行使用メモリ 52,460 KB
最終ジャッジ日時 2023-09-10 21:21:46
合計ジャッジ時間 8,730 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
5,576 KB
testcase_03 AC 8 ms
4,956 KB
testcase_04 AC 3 ms
4,380 KB
testcase_05 AC 3 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
5,492 KB
testcase_08 AC 304 ms
52,260 KB
testcase_09 AC 302 ms
52,208 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 306 ms
52,460 KB
testcase_14 AC 314 ms
52,268 KB
testcase_15 AC 76 ms
23,140 KB
testcase_16 AC 311 ms
52,212 KB
testcase_17 AC 360 ms
52,240 KB
testcase_18 AC 97 ms
19,052 KB
testcase_19 AC 212 ms
33,284 KB
testcase_20 AC 534 ms
52,240 KB
testcase_21 AC 525 ms
52,384 KB
testcase_22 AC 539 ms
52,324 KB
testcase_23 AC 535 ms
52,280 KB
testcase_24 AC 91 ms
23,164 KB
testcase_25 AC 93 ms
23,040 KB
testcase_26 AC 388 ms
52,252 KB
testcase_27 AC 394 ms
52,208 KB
testcase_28 AC 365 ms
52,252 KB
testcase_29 AC 362 ms
52,256 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 3 ms
4,380 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 3 ms
4,380 KB
testcase_35 AC 2 ms
4,380 KB
testcase_36 AC 3 ms
4,380 KB
testcase_37 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0;i < n;i++)
#define REP(i,n,k) for(int i = n;i < k;i++)
#define P(p) cout<<(p)<<endl;
#define pi 3.1415926535
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int dx[] = { 0, 1, 0, -1 };
int dy[] = { -1, 0, 1, 0 };

unsigned long long sttoi(std::string str) {
	unsigned long long ret;
	std::stringstream ss; ss << str;
	ss >> ret;
	return ret;
}

ll gcd(ll a, ll b){
	if (b > a)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a%b);
}
int visited[50][50][5000];
void solve() {
	int h, w, a, sx, sy, b, gx, gy;
	cin >> h >> w >> a >> sy >> sx >> b >> gy >> gx;
	int field[50][50];
	for (int i = 0; i < h; i++){
		string s;
		cin >> s;
		for (int j = 0; j < w; j++){
			field[i][j] = s[j] == '.' ? 0 : 1;
		}
	}
	queue<pair<pair<int, int>, int> > que;
	que.push(make_pair(make_pair(sx, sy), a));
	visited[sy][sx][a] = 1;
	while (!que.empty()){
		int x = que.front().first.first;
		int y = que.front().first.second;
		int s = que.front().second;
		visited[y][x][s] = 1;
		que.pop();
		if (s > 0){
			for (int i = 0; i < 4; i++){
				int nx = x + dx[i];
				int ny = y + dy[i];
				if (nx >= 0 && nx < w && ny >= 0 && ny < h && s + 1 < 5000){
					int ns;
					if (field[ny][nx] == 1) ns = s + 1;
					else ns = s - 1;
					if (visited[ny][nx][ns] != 1){
						visited[ny][nx][ns] = 1;
						que.push(make_pair(make_pair(nx, ny), ns));
					}
				}
			}
		}
	}
	P(visited[gy][gx][b] ? "Yes" : "No");
}

int main() {
	solve();
	return 0;
}
0