結果
| 問題 |
No.240 ナイト散歩
|
| ユーザー |
|
| 提出日時 | 2018-12-26 16:31:09 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 715 bytes |
| コンパイル時間 | 587 ms |
| コンパイル使用メモリ | 63,244 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-10-01 14:44:05 |
| 合計ジャッジ時間 | 1,340 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 30 |
ソースコード
#include <iostream>
using namespace std;
int X, Y;
bool walk(int a, int b, int stepCount) {
if (a == X && b == Y) return true;
if (stepCount == 3) return false;
if (walk(a - 2, b - 1, stepCount + 1)) return true;
if (walk(a - 2, b + 1, stepCount + 1)) return true;
if (walk(a - 1, b - 2, stepCount + 1)) return true;
if (walk(a - 1, b + 2, stepCount + 1)) return true;
if (walk(a + 1, b - 2, stepCount + 1)) return true;
if (walk(a + 1, b + 2, stepCount + 1)) return true;
if (walk(a + 2, b - 1, stepCount + 1)) return true;
if (walk(a + 2, b + 1, stepCount + 1)) return true;
return false;
}
int main() {
cin >> X >> Y;
if (walk(0, 0, 0)) cout << "YES";
else cout << "NO";
}