結果

問題 No.240 ナイト散歩
ユーザー alpha_virginis
提出日時 2015-07-10 22:37:37
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 516 bytes
コンパイル時間 1,415 ms
コンパイル使用メモリ 158,744 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-10-07 20:49:29
合計ジャッジ時間 2,083 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

int gx, gy;

bool solve(int d, int x, int y) {
  if( x == gx && y == gy ) return true;
  if( d == 0 ) return false;

  int dx[8] = {-2, -2, -1, -1, 1, 1, 2, 2};
  int dy[8] = {-1, 1, -2, 2, -2, 2, -1, 1};

  for(int i = 0; i < 8; ++i) {
    if( solve(d - 1, x + dx[i], y + dy[i]) ) return true;
  }

  return false;
}

int main() {

  std::cin >> gx >> gy;

  if( solve(3, 0, 0) ) {
    std::cout << "YES" << std::endl;
  }
  else {
    std::cout << "NO" << std::endl;
  }
  
  return 0;
}
0