結果

問題 No.240 ナイト散歩
コンテスト
ユーザー yuppe19 😺
提出日時 2015-07-11 18:32:49
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 984 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 447 ms
コンパイル使用メモリ 90,228 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-04-24 07:56:54
合計ジャッジ時間 1,542 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;

class range {private: struct I{int x;int operator*(){return x;}bool operator!=(I& lhs){return x<lhs.x;}void operator++(){++x;}};I i,n;
public:range(int n):i({0}),n({n}){}range(int i,int n):i({i}),n({n}){}I& begin(){return i;}I& end(){return n;}};

struct Point { int x, y, c; };
vector<int> dx = {2,  2, 1,  1, -1, -1, -2, -2},
            dy = {1, -1, 2, -2,  2, -2,  1, -1};

bool nya(int x, int y, int times) {
  queue<Point> que;
  que.push(Point({x, y, times}));
  while(!que.empty()) {
    Point cur = que.front(); que.pop();
    if(cur.c < 0) { continue; }
    if(cur.x == 0 && cur.y == 0) { return true; }
    for(int i : range(dx.size())) {
      int nx = cur.x + dx[i],
          ny = cur.y + dy[i],
          nc = cur.c - 1;
      que.push(Point({nx, ny, nc}));
    }
  }
  return false;
}

int main(void) {
  int x, y; scanf("%d%d", &x, &y);
  puts(nya(x, y, 3) ? "YES" : "NO");
  return 0;
}
0