結果
| 問題 | No.323 yuki国 |
| コンテスト | |
| ユーザー |
bal4u
|
| 提出日時 | 2019-07-07 18:28:30 |
| 言語 | C (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 54 ms / 5,000 ms |
| コード長 | 1,387 bytes |
| 記録 | |
| コンパイル時間 | 424 ms |
| コンパイル使用メモリ | 30,848 KB |
| 実行使用メモリ | 23,684 KB |
| 最終ジャッジ日時 | 2024-10-05 03:36:00 |
| 合計ジャッジ時間 | 2,125 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 6 |
| other | AC * 32 |
コンパイルメッセージ
main.c: In function 'in':
main.c:7:14: warning: implicit declaration of function 'getchar_unlocked' [-Wimplicit-function-declaration]
7 | #define gc() getchar_unlocked()
| ^~~~~~~~~~~~~~~~
main.c:13:24: note: in expansion of macro 'gc'
13 | int n = 0, c = gc();
| ^~
ソースコード
// yukicoder: 323 yuki国
// 2019.7.7 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); while ((c = gc()) >= '0');
return n;
}
void ins(char *s) // 文字列の入力 スペース以下の文字で入力終了
{
do *s = gc();
while (*s++ > ' ');
*(s-1) = 0;
}
#define QMAX 10000000
typedef struct { char r, c; int a; } Q;
Q q[QMAX+5]; int top;
int H, W, lim, sr, sc, gr, gc, A, B;
char map[53][53];
char vis[53][53][1200];
int mv[4][2] = {{-1,0},{0,1},{1,0},{0,-1}};
int bfs() {
int i, r, c, a, rr, cc;
q[0].r = sr, q[0].c = sc, q[0].a = A, top = 1;
while (top) {
r = q[--top].r, c = q[top].c, a = q[top].a;
// printf("r=%d, c=%d, a=%d\n", r, c, a);
if (r == gr && c == gc && a == B) return 1;
if (!a || a == lim) continue;
if (vis[r][c][a]) continue;
vis[r][c][a] = 1;
for (i = 0; i < 4; i++) {
rr = r + mv[i][0], cc = c + mv[i][1];
if (rr < 0 || rr >= H || cc < 0 || cc >= W) continue;
q[top].r = rr, q[top].c = cc, q[top++].a = a + (map[rr][cc] == '*'? 1: -1);
}
}
return 0;
}
int main()
{
int i, r, c;
H = in(), W = in();
A = in(), sr = in(), sc = in();
B = in(), gr = in(), gc = in();
for (r = 0; r < H; r++) ins(map[r]);
lim = (A >= B? A: B) + H + W;
puts(bfs()? "Yes": "No");
return 0;
}
bal4u