結果
問題 | No.240 ナイト散歩 |
ユーザー | koyumeishi |
提出日時 | 2015-07-10 22:37:28 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 819 bytes |
コンパイル時間 | 834 ms |
コンパイル使用メモリ | 82,280 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-10-07 20:49:21 |
合計ジャッジ時間 | 1,698 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 30 |
ソースコード
#include <iostream> #include <vector> #include <cstdio> #include <sstream> #include <map> #include <string> #include <algorithm> #include <queue> #include <cmath> #include <set> using namespace std; long long dx[] = {-2,-2,-1,-1,1,1,2,2}; long long dy[] = {-1,1,-2,2,-2,2,-1,1}; int main(){ long long X,Y; cin >> X >> Y; bool ok = false; queue<pair<long long, long long>> pos; queue<int> dist; pos.push({0,0}); dist.push(0); while(pos.size()){ long long x = pos.front().first; long long y = pos.front().second; pos.pop(); int d = dist.front(); dist.pop(); if(x == X && y == Y) ok = true; if(d+1 > 3) continue; for(int i=0; i<8; i++){ long long x_ = x + dx[i]; long long y_ = y + dy[i]; pos.push({x_,y_}); dist.push(d+1); } } cout << (ok?"YES":"NO") << endl; return 0; }