結果
問題 | No.240 ナイト散歩 |
ユーザー |
![]() |
提出日時 | 2015-07-25 18:54:05 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,258 bytes |
コンパイル時間 | 701 ms |
コンパイル使用メモリ | 88,084 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-10-07 21:00:15 |
合計ジャッジ時間 | 1,635 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 30 |
ソースコード
#include <iostream> #include <algorithm> #include <functional> #include <string> #include <climits> #include <vector> #include <numeric> #include <complex> #include <map> #include <bitset> #include <queue> using namespace std; //#define __int64 long long //#define long __int64 #define REP(i,a,b) for(int i=a;i<b;i++) #define rep(i,n) REP(i,0,n) const int Vecy[8] = {-1,1,-2,2,-2,2,-1,1}; const int Vecx[8] = {-2,-2,-1,-1,1,1,2,2}; int main(){ int field[21][21]; int x,y; int cx,cy; int nx,ny; queue< pair<int,int> > next; cin >> x >> y; rep(iy,21){ rep(ix,21){ field[iy][ix] = -1; } } if(abs(x) > 10 || abs(y) > 10){ cout << "NO" << endl; return 0; } next.push(make_pair(10,10)); field[10][10] = 0; while(!next.empty()){ cx = next.front().first; cy = next.front().second; next.pop(); if(field[cx][cy] <= 2){ rep(i,8){ nx = cx + Vecx[i]; ny = cy + Vecy[i]; if(field[nx][ny] == -1){ next.push(make_pair(nx, ny)); field[nx][ny] = field[cx][cy] + 1; } } } } /* rep(iy,21){ rep(ix,21){ cout << (field[iy][ix] == -1 ? "□" : "■"); } cout << endl; } */ if(field[x + 10][y + 10] != -1){ cout << "YES" << endl; }else{ cout << "NO" << endl; } return 0; }