結果
| 問題 |
No.240 ナイト散歩
|
| ユーザー |
bal4u
|
| 提出日時 | 2019-04-15 20:49:55 |
| 言語 | C (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 1 ms / 2,000 ms |
| コード長 | 792 bytes |
| コンパイル時間 | 118 ms |
| コンパイル使用メモリ | 30,464 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-09-22 08:02:17 |
| 合計ジャッジ時間 | 1,222 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 30 |
ソースコード
// yukicoder: No.240 ナイト散歩
// 2019.4.15 bal4u
#include <stdio.h>
#define BASE 10
typedef struct { int x, y, s; } Q;
Q q[1000]; int top, end;
int mv[8][2] = {{-2,-1},{-2,1},{-1,-2},{-1,2},{1,-2},{1,2},{2,-1},{2,1}};
char map[20][20];
int main()
{
int i, x, y, s, xx, yy, ans;
q[0].x = BASE, q[0].y = BASE, q[0].s = 0, top = 0, end = 1;
while (top != end) {
x = q[top].x, y = q[top].y, s = q[top++].s;
if (map[x][y]) continue;
map[x][y] = 1;
if (s == 3) continue;
for (i = 0; i < 8; i++) {
xx = x + mv[i][0], yy = y + mv[i][1];
if (!map[xx][yy]) q[end].x = xx, q[end].y = yy, q[end++].s = s + 1;
}
}
scanf("%d%d", &x, &y);
x += BASE, y += BASE;
ans = 0;
if (x >= 0 && y >= 0 && x <= 20 && y <= 20) ans = map[x][y];
puts(ans ? "YES" : "NO");
return 0;
}
bal4u