結果

問題 No.424 立体迷路
ユーザー bal4ubal4u
提出日時 2019-05-13 19:00:17
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 1,605 bytes
コンパイル時間 225 ms
コンパイル使用メモリ 30,212 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-18 17:06:48
合計ジャッジ時間 1,270 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 0 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 0 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 0 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 0 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 0 ms
4,376 KB
testcase_17 AC 0 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 1 ms
4,384 KB
testcase_20 AC 0 ms
4,376 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 1 ms
4,500 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: 関数 ‘in’ 内:
main.c:7:14: 警告: 関数 ‘getchar_unlocked’ の暗黙的な宣言です [-Wimplicit-function-declaration]
    7 | #define gc() getchar_unlocked()
      |              ^~~~~~~~~~~~~~~~
main.c:13:24: 備考: in expansion of macro ‘gc’
   13 |         int n = 0, c = gc();
      |                        ^~

ソースコード

diff #

// yukicoder: No.424 立体迷路
// 2019.5.13 bal4u

#include <stdio.h>

#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif
int in()
{
	int n = 0, c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

void ins(char *s)  // 文字列の入力 スペース以下の文字で入力終了
{
	int c;
	do c = gc(), *s++ = c & 0xf;
	while (c > ' ');
//	*(s-1) = 0;
}

typedef struct { char r, c; } Q;
Q q[10000000]; int top, end;
int H, W;
char map[52][52];
char vis[52][52];
int mv1[4][2] = {{-1,0},{0,1},{1,0},{0,-1}};
int mv2[4][2] = {{-2,0},{0,2},{2,0},{0,-2}};

int dfs(int sr, int sc, int gr, int gc) {
	int i, r, c, rr, cc, r2, c2;
	
	q[0].r = sr, q[0].c = sc, top = 0, end = 1;
	while (top != end) {
		r = q[top].r, c = q[top++].c;
		if (r == gr && c == gc) return 1;
		if (vis[r][c]) continue;
		vis[r][c] = 1;
		for (i = 0; i < 4; i++) {
			rr = r + mv1[i][0], cc = c + mv1[i][1];
			if (rr < 0 || rr >= H || cc < 0 || cc >= W) continue;
			if (map[rr][cc] == map[r][c] || map[rr][cc] == map[r][c]+1 ||
			    map[rr][cc] == map[r][c]-1) {
				if (!vis[rr][cc]) q[end].r = rr, q[end++].c = cc;
			}
			r2 = r + mv2[i][0], c2 = c + mv2[i][1];
			if (r2 < 0 || r2 >= H || c2 < 0 || c2 >= W) continue;
			if (map[r2][c2] == map[r][c] && map[rr][cc] < map[r][c]) {
				if (!vis[r2][c2]) q[end].r = r2, q[end++].c = c2;
			}
		}
	}
	return 0;
}

int main()
{
	int r, c;
	int sr, sc, gr, gc;

	H = in(), W = in();
	sr = in()-1, sc = in()-1, gr = in()-1, gc = in()-1;
	for (r = 0; r < H; r++) ins(map[r]);
	puts(dfs(sr, sc, gr, gc)? "YES": "NO");
	return 0;
}
0