結果

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

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

typedef pair<int, int> PII;

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

bool move(PII pos, int n_move) {
	if (n_move > 3) {
		return false;
	}

	if (x == pos.first && y == pos.second) {
		return true;
	}

	for (int i = 0; i < 8; i++) {
		bool ret = move(make_pair(pos.first + dx[i], pos.second + dy[i]), n_move + 1);
		if (ret) {
			return true;
		}
	}

	return false;
}

int main() {
	cin >> x >> y;
	bool ret = move(make_pair(0, 0), 0);
	cout << (ret ? "YES" : "NO") << endl;
}
0