// yukicoder: No.240 ナイト散歩 // 2019.4.15 bal4u #include #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; }