結果

問題 No.323 yuki国
ユーザー FF256grhyFF256grhy
提出日時 2015-12-16 16:32:21
言語 C++11
(gcc 11.4.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,664 bytes
コンパイル時間 314 ms
コンパイル使用メモリ 27,540 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-10-14 10:47:25
合計ジャッジ時間 2,276 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,372 KB
testcase_01 AC 1 ms
4,372 KB
testcase_02 AC 2 ms
4,368 KB
testcase_03 AC 1 ms
4,372 KB
testcase_04 AC 1 ms
4,368 KB
testcase_05 AC 1 ms
4,372 KB
testcase_06 AC 2 ms
4,372 KB
testcase_07 AC 1 ms
4,368 KB
testcase_08 AC 2 ms
4,368 KB
testcase_09 AC 1 ms
4,372 KB
testcase_10 AC 2 ms
4,372 KB
testcase_11 AC 1 ms
4,368 KB
testcase_12 AC 2 ms
4,368 KB
testcase_13 AC 1 ms
4,368 KB
testcase_14 AC 2 ms
4,368 KB
testcase_15 AC 22 ms
4,372 KB
testcase_16 AC 73 ms
4,372 KB
testcase_17 AC 2 ms
4,368 KB
testcase_18 AC 1 ms
4,372 KB
testcase_19 AC 1 ms
4,368 KB
testcase_20 AC 2 ms
4,368 KB
testcase_21 AC 1 ms
4,368 KB
testcase_22 AC 2 ms
4,372 KB
testcase_23 AC 1 ms
4,368 KB
testcase_24 AC 33 ms
4,368 KB
testcase_25 AC 1 ms
4,368 KB
testcase_26 AC 39 ms
4,368 KB
testcase_27 AC 2 ms
4,372 KB
testcase_28 AC 2 ms
4,368 KB
testcase_29 AC 2 ms
4,368 KB
testcase_30 AC 2 ms
4,368 KB
testcase_31 AC 1 ms
4,368 KB
testcase_32 AC 1 ms
4,368 KB
testcase_33 AC 1 ms
4,368 KB
testcase_34 AC 1 ms
4,368 KB
testcase_35 WA -
testcase_36 AC 1 ms
4,368 KB
testcase_37 AC 1 ms
4,372 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

int h, w, a, si, sj, b, gi, gj;
char m[51][51];
int max_val[50][50], min_val[50][50];

int di[4] = {1, 0, -1,  0};
int dj[4] = {0, 1,  0, -1};

int max_search(int pi, int pj, int v, int is_pp) {
	if( ! (0 <= pi && pi < h && 0 <= pj && pj < w) ) { return 0; }
	if(m[pi][pj] == '*') { v++; } else { v--; }
	if(m[pi][pj] == '*' && is_pp) { return 1; }
	if(v <= max_val[pi][pj]) { return 0; }
	max_val[pi][pj] = v;
	
	int i, ret = 0;
	for(i = 0; i < 4; i++) {
		ret = max_search(pi + di[i], pj + dj[i], v, (m[pi][pj] == '*'));
		if(ret) { break; }
	}
	return ret;
}

void min_search(int pi, int pj, int v) {
	if( ! (0 <= pi && pi < h && 0 <= pj && pj < w) ) { return; }
	if(m[pi][pj] == '*') { v++; } else { v--; }
	if(v == 0) { v = 2; }
	if(min_val[pi][pj] != 0 && v >= min_val[pi][pj]) { return; }
	min_val[pi][pj] = v;
	
	int i;
	for(i = 0; i < 4; i++) {
		min_search(pi + di[i], pj + dj[i], v);
	}
	return;
}

int main(void) {
	scanf("%d%d%d%d%d%d%d%d%", &h, &w, &a, &si, &sj, &b, &gi, &gj);
	
	if( ((b - a) + (gi - si) + (gj - sj)) % 2 != 0 ) { printf("No\n"); return 0; }
	
	int i, j;
	for(i = 0; i < h; i++) {
		scanf("%s", m[i]);
	}
	
	int has_p = 0, has_m = 0;
	for(i = 0; i < h; i++) {
	for(j = 0; j < w; j++) {
		if( m[i][j] == '.' && (m[i][j + 1] == '.' || m[i + 1][j] == '.') ) { has_m = 1; }
	}
	}
	
	int c;
	if(m[si][sj] == '*') { c = 1; } else { c = -1; }
	
	int ans = 0;
	if( max_search(si, sj, a - c, 0) == 0 ) {
		if( (has_m && max_val[gi][gj] >= b) || (max_val[gi][gj] == b) ) { ans = 1; }
	} else {
		min_search(si, sj, a - c);
		if(min_val[gi][gj] <= b) { ans = 1; }
	}
	
	printf("%s\n", (ans ? "Yes" : "No"));
	
	return 0;
}
0