結果
| 問題 |
No.240 ナイト散歩
|
| ユーザー |
|
| 提出日時 | 2016-05-03 20:42:03 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 1,179 bytes |
| コンパイル時間 | 742 ms |
| コンパイル使用メモリ | 67,712 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-10-07 21:24:45 |
| 合計ジャッジ時間 | 1,778 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 30 |
ソースコード
#include <iostream>
#include <utility>
#include <queue>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int x, y;
cin >> x >> y;
pair<int, int> aimPos = make_pair(x, y);
pair<int, int> knightPos(0, 0);
vector<pair<int, int>> knightMove{make_pair(-2,-1), make_pair(-2,1),
make_pair(-1, 2), make_pair(1,2),
make_pair(2,1), make_pair(2,-1),
make_pair(1,-2), make_pair(-1,-2) };
bool arrival = false;
bool knightThreeStep = false;
queue<pair<int, int>> q;
q.push(knightPos);
while (!q.empty()) {
knightPos = q.front();
if (knightPos == aimPos) {
arrival = true;
break;
}
q.pop();
if (knightThreeStep == false) {
for (int i = 0; i < 8; ++i) {
q.push(make_pair(knightPos.first + knightMove.at(i).first, knightPos.second + knightMove.at(i).second));
}
}
if (q.size() == 512) knightThreeStep = true; //8^3
}
cout << (arrival ? "YES" : "NO") << endl;
return 0;
}