結果
| 問題 |
No.240 ナイト散歩
|
| ユーザー |
hogeover30
|
| 提出日時 | 2016-06-17 01:28:19 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 757 bytes |
| コンパイル時間 | 1,100 ms |
| コンパイル使用メモリ | 91,712 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-10-07 21:26:38 |
| 合計ジャッジ時間 | 1,841 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 30 |
ソースコード
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
using namespace std;
int dr[]={-2, -2, -1, -1, 1, 1, 2, 2};
int dc[]={-1, 1, -2, 2, -2, 2, -1, 1};
int main()
{
int x, y;
cin>>x>>y;
pair<int, int> goal(x, y);
queue<pair<int, int>> q;
map<pair<int, int>, int> v;
q.emplace(0, 0);
v[make_pair(0, 0)]=0;
bool ok=false;
while (!q.empty()) {
auto p=q.front();
q.pop();
if (p==goal) { ok=true; break; }
if (v[p]==3) continue;
for(int i=0; i<8; ++i) {
auto np=make_pair(p.first+dr[i], p.second+dc[i]);
if (v.count(np)) continue;
q.emplace(np);
v[np]=v[p]+1;
}
}
cout<<(ok ? "YES" : "NO")<<endl;
}
hogeover30