結果

問題 No.20 砂漠のオアシス
ユーザー bal4ubal4u
提出日時 2019-04-10 10:07:08
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 1,213 bytes
コンパイル時間 865 ms
コンパイル使用メモリ 29,432 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-20 18:06:48
合計ジャッジ時間 3,059 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

// yukicoder: No.20 砂漠のオアシス
// 2019.4.10 bal4u
// 深さ優先探索 dfs

#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;
}

typedef struct { int r, c, v; } Q;
Q q[2000000]; int top;
int N, V, OR, OC;
int map[205][205];
int val[205][205];
int mv[4][2] = { {-1,0},{0,1},{1,0},{0,-1} };

int dfs(int sr, int sc, int gr, int gc)
{
	int i, r, c, v, rr, cc, vv;

	q[0].r = sr, q[0].c = sc, q[0].v = V, top = 1;
	while (top) {
		r = q[--top].r, c = q[top].c, v = q[top].v;
		if (r == gr && c == gc) return 1;
		if (val[r][c] >= v) continue;
		val[r][c] = v;
		for (i = 0; i < 4; i++) {
			rr = r + mv[i][0], cc = c + mv[i][1];
			if (rr < 0 || rr >= N || cc < 0 || cc >= N) continue;
			if ((vv = v - map[rr][cc]) < 0) continue;
			if (rr == OR && cc == OC) vv <<= 1;
			if (val[rr][cc] < vv) q[top].r = rr, q[top].c = cc, q[top++].v = vv;
		}
	}
	return 0;
}

int main()
{
	int r, c;

	N = in(), V = in(), OR = in()-1, OC = in()-1;
	for (r = 0; r < N; r++) for (c = 0; c < N; c++) map[r][c] = in();
	puts(dfs(0, 0, N - 1, N - 1) ? "YES" : "NO");
	return 0;
}
0