結果
問題 | No.240 ナイト散歩 |
ユーザー |
![]() |
提出日時 | 2016-08-23 21:30:03 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 786 bytes |
コンパイル時間 | 652 ms |
コンパイル使用メモリ | 70,508 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-10-07 21:27:49 |
合計ジャッジ時間 | 1,537 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 30 |
ソースコード
#include <iostream> #include <vector> #include <queue> #include <cstdio> #include <algorithm> using namespace std; #define rep(i,n) for(int i=0;i<(n);i++) int dx[8] = {-2, -2, -1, -1, 1, 1, 2, 2}; int dy[8] = {-1, 1, -2, 2, -2, 2, -1, 1}; // (x-2,y-1),(x-2,y+1),(x-1,y-2),(x-1,y+2),(x+1,y-2),(x+1,y+2),(x+2,y-1),(x+2,y+1) int main(void){ int a, b; cin >> a >> b; //X, Y queue<pair<int, int> > q; queue<int> num; q.push(make_pair(0, 0)); num.push(0); while(!q.empty()){ auto now = q.front(); q.pop(); auto cnt = num.front(); num.pop(); if(cnt >= 3) continue; rep(i, 8){ int y = now.first + dy[i]; int x = now.second + dx[i]; if(y == b && x == a){ printf("YES\n"); return 0; } q.push(make_pair(y, x)); num.push(cnt + 1); } } printf("NO\n"); }