結果
| 問題 |
No.240 ナイト散歩
|
| コンテスト | |
| ユーザー |
Captain
|
| 提出日時 | 2019-10-21 22:20:00 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 813 bytes |
| コンパイル時間 | 1,659 ms |
| コンパイル使用メモリ | 175,364 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-02 17:51:42 |
| 合計ジャッジ時間 | 2,362 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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 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 == 3)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;
}
Captain