結果

問題 No.240 ナイト散歩
ユーザー nayutanayuta
提出日時 2019-12-20 23:19:15
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 625 bytes
コンパイル時間 1,630 ms
コンパイル使用メモリ 175,060 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-18 01:47:05
合計ジャッジ時間 2,728 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 25 WA * 5
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

typedef tuple<int, int, int> TP;
const int dx[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int dy[] = {-1, 1, -2, 2, -2, 2, -1, 1};

int main() {
  int x, y;
  cin >> x >> y;

  queue<TP> que;
  que.emplace(0, 0, 0);
  while (!que.empty()) {
    int cx, cy, c;
    tie(cx, cy, c) = que.front();
    que.pop();
    for (int i = 0; i < 8; i++) {
      int nx = cx + dx[i];
      int ny = cy + dy[i];

      if (nx == x && ny == y) {
        cout << "YES" << endl;
        return 0;
      }
      if (c != 3) que.emplace(nx, ny, c + 1);
    }
  }
  cout << "NO" << endl;

  return 0;
}
0