結果
問題 |
No.240 ナイト散歩
|
ユーザー |
![]() |
提出日時 | 2019-10-21 22:06:04 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 812 bytes |
コンパイル時間 | 1,652 ms |
コンパイル使用メモリ | 175,380 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-02 17:51:47 |
合計ジャッジ時間 | 2,700 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 25 WA * 5 |
ソースコード
#include<bits/stdc++.h> using namespace std; using ll =long long; #define rep(i,N) for(int (i)=0;(i)<(N);++(i)) #define SORT(i) sort((i).begin(),(i).end()) constexpr ll INF = 2000000000; constexpr ll mod = 10e8 + 7; int main() { int x, y; cin >> x >> y; int cy[8] = { -1,1,-2,2,-2,2,-1,1 }; int cx[8] = { -2,-2,-1,-1,1,1,2,2 }; queue<pair<int, int>>que; queue<int>dist; que.push(make_pair(0, 0)); dist.push(0); int ny, nx; while (!que.empty()) { pair<int, int>N = que.front(); que.pop(); int d = dist.front(); dist.pop(); int a; if (d == 4)break; rep(i, 8) { nx = N.first + cx[i], ny = N.second + cy[i]; a = d + 1; if (nx == x && ny == y) { cout << "YES" << "\n"; return 0; } que.push(make_pair(nx, ny)); dist.push(a); } } cout << "NO" << "\n"; return 0; }