結果
問題 | No.240 ナイト散歩 |
ユーザー |
![]() |
提出日時 | 2015-01-10 12:28:29 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,273 bytes |
コンパイル時間 | 1,794 ms |
コンパイル使用メモリ | 92,684 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-10-07 20:45:21 |
合計ジャッジ時間 | 1,724 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 30 |
ソースコード
#include <algorithm> #include <cfloat> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iostream> #include <map> #include <memory> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; #define sz size() #define pb push_back #define mp make_pair #define fi first #define se second #define all(c) (c).begin(), (c).end() #define rep(i,a,b) for(int i=(a);i<(b);++i) #define clr(a, b) memset((a), (b) ,sizeof(a)) #define MOD 1000000009 int main(){ static int dx[8]={-2, -2, -1, -1, 1, 1, 2, 2}; static int dy[8]={-1, 1, -2, 2, -2, 2, -1, 1}; int x,y; cin>>x>>y; queue<int> qx,qy,qc; qx.push(0); qy.push(0); qc.push(0); while(!qx.empty()){ int x1 = qx.front();qx.pop(); int y1 = qy.front();qy.pop(); int c1 = qc.front();qc.pop(); if(c1>3)continue; if(x1==x&&y1==y){ cout << "YES" << endl; return 0; } rep(i,0,8){ qx.push(x1+dx[i]); qy.push(y1+dy[i]); qc.push(c1+1); } } cout << "NO" << endl; return 0; } /* 幅優先探索か深さ3で打ち切りの深さ優先探索でいけると思います。 */