結果
問題 | No.240 ナイト散歩 |
ユーザー |
![]() |
提出日時 | 2019-10-20 08:15:55 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 788 bytes |
コンパイル時間 | 1,702 ms |
コンパイル使用メモリ | 174,668 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-28 19:04:49 |
合計ジャッジ時間 | 2,527 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 30 |
ソースコード
#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 int INF = 2000000000;constexpr ll mod = 1000000007;int dx[8] = { -2, -2, -1, -1, 1, 1, 2, 2 };int dy[8] = { -1, 1, -2, 2, -2, 2, -1, 1 };int main() {int a, b; cin >> a >> b;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) {cout << "YES" << "\n";return 0;}q.push(make_pair(y, x));num.push(cnt + 1);}}cout << "NO" << "\n";return 0;}