結果
問題 | No.240 ナイト散歩 |
ユーザー |
![]() |
提出日時 | 2019-04-26 20:50:09 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,860 bytes |
コンパイル時間 | 763 ms |
コンパイル使用メモリ | 82,340 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-25 00:29:10 |
合計ジャッジ時間 | 1,714 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 30 |
ソースコード
#include <iostream> #include <vector> #include <algorithm> #include <map> #include <string> #include <queue> #include <stack> #include <math.h> #include <set> #define ALL(obj) (obj).begin(),(obj).end() #define RALL(obj) (obj).rbegin(),(obj).rend() #define P pair<int, int> #define MOD 1000000007 #define INF 1012345678 #define NINF (-2147483647-1) #define LLINF 9223372036854775807 using ll = long long; using namespace std; struct C { int x, y; }; int main() { int X, Y; cin >> X >> Y; const int N = 3; //進める回数 const int dx[] = {-2,-2,-1,-1, 1, 1, 2, 2}; const int dy[] = {-1, 1,-2, 2,-2, 2,-1, 1}; vector<vector<bool>> visited(4 * N + 1, vector<bool>(4 * N + 1, false)); //通った座標の記録 queue<pair<C, int>> q; q.push(pair<C, int>(C{0,0}, 0)); while (!q.empty()) { pair<C, int> p = q.front(); q.pop(); if (visited[p.first.x + 2 * N][p.first.y + 2 * N]) continue; visited[p.first.x + 2 * N][p.first.y + 2 * N] = true; if (p.second < N) { for (int i = 0; i < 8; i++) { q.push(pair<C, int>(C{p.first.x + dx[i], p.first.y + dy[i]}, p.second + 1)); } } } if (X >= -2 * N && Y >= -2 * N && X <= 2 * N && Y <= 2 * N && visited[X + 2 * N][Y + 2 * N]) { cout << "YES" << endl; } else { cout << "NO" << endl; } // 試しに表示してみる /* for (int i = -2 * N; i <= 2 * N; i++) { for (int j = -2 * N; j <= 2 * N; j++) { if (i == 0 && j == 0) { cout << "%"; } else if (visited[i+2 * N][j+2 * N]) { cout << "#"; } else { cout << "."; } } cout << endl; } */ getchar(); getchar(); return 0; }