結果
問題 | No.240 ナイト散歩 |
ユーザー |
![]() |
提出日時 | 2017-07-28 02:16:40 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 985 bytes |
コンパイル時間 | 1,099 ms |
コンパイル使用メモリ | 94,288 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-10 02:30:40 |
合計ジャッジ時間 | 2,204 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 30 |
ソースコード
#include <algorithm> #include <cstdio> #include <iostream> #include <map> #include <cmath> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> #include <stdlib.h> #include <stdio.h> #include <bitset> using namespace std; #define FOR(I,A,B) for(int I = (A); I < (B); ++I) typedef long long ll; typedef pair<ll, ll> P; typedef pair<ll, P> PP; int main() { ll X, Y; cin >> X >> Y; if(0 == X && 0 == Y) { puts("YES"); return 0; } queue<PP> Q; Q.push(PP(0,P(0,0))); // y, x int vy[8] = {-1,1,-2,2,-2,2,-1,1}; int vx[8] = {-2,-2,-1,-1,1,1,2,2}; while(!Q.empty()) { PP pp = Q.front();Q.pop(); ll t = pp.first; ll y = pp.second.first; ll x = pp.second.second; if(t >= 3) continue; FOR(i,0,8) { ll nx = x + vx[i]; ll ny = y + vy[i]; if(nx == X && ny == Y) { puts("YES"); return 0; } Q.push(PP(t+1,P(ny,nx))); } } puts("NO"); return 0; }