結果
| 問題 |
No.20 砂漠のオアシス
|
| コンテスト | |
| ユーザー |
bal4u
|
| 提出日時 | 2019-04-10 12:46:06 |
| 言語 | C (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 529 ms / 5,000 ms |
| コード長 | 1,357 bytes |
| コンパイル時間 | 498 ms |
| コンパイル使用メモリ | 30,720 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-06 22:19:31 |
| 合計ジャッジ時間 | 2,323 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 21 |
コンパイルメッセージ
main.c: In function 'in':
main.c:9:14: warning: implicit declaration of function 'getchar_unlocked' [-Wimplicit-function-declaration]
9 | #define gc() getchar_unlocked()
| ^~~~~~~~~~~~~~~~
main.c:15:24: note: in expansion of macro 'gc'
15 | int n = 0, c = gc();
| ^~
ソースコード
// yukicoder: No.20 砂漠のオアシス
// 2019.4.10 bal4u
// 深さ優先探索 dfs
#include <stdio.h>
#include <string.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; char f; } Q;
Q q[20000]; int top;
int N, OR, OC;
int map[205][205];
int val[205][205][2];
int mv[4][2] = { {-1,0},{0,1},{1,0},{0,-1} };
int dfs(int sr, int sc, int gr, int gc, int v)
{
int i, r, c, f, rr, cc, vv;
memset(val, -1, sizeof(val));
q[0].r = sr, q[0].c = sc, q[0].v = v, q[0].f = 0, top = 1;
while (top) {
r = q[--top].r, c = q[top].c, v = q[top].v, f = q[top].f;
if (r == gr && c == gc) return 1;
if (val[r][c][f] >= v) continue;
val[r][c][f] = 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 (!f && rr == OR && cc == OC) vv <<= 1, f = 1;
if (val[rr][cc][f] < vv) {
q[top].r = rr, q[top].c = cc, q[top].v = vv, q[top++].f = f;
}
}
}
return 0;
}
int main()
{
int r, c, V;
N = in(), V = in(), OC = in()-1, OR = 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, V) ? "YES" : "NO");
return 0;
}
bal4u