結果
| 問題 |
No.240 ナイト散歩
|
| コンテスト | |
| ユーザー |
Captain
|
| 提出日時 | 2019-10-20 00:24:27 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 913 bytes |
| コンパイル時間 | 1,681 ms |
| コンパイル使用メモリ | 175,508 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-28 02:46:33 |
| 合計ジャッジ時間 | 7,315 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 RE * 1 |
| other | AC * 1 RE * 4 TLE * 1 -- * 24 |
ソースコード
#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 main() {
int gx, gy; cin >> gx >> gy;
gy = abs(gy), gx = abs(gx);
vector<vector<int>>dist(gy, vector<int>(gx, -1));
queue<pair<int, int>>que;
--gx, --gy;
dist[0][0] = 0;
que.push(make_pair(0, 0));
int ny, nx;
int y[8] = { -1,1,-2,2,-2,2,-1,1 };
int x[8] = { -2,-2,-1,-1,1,1,2,2 };
while (!que.empty()) {
pair<int, int>N = que.front();
que.pop();
rep(i, 8) {
ny = N.first + y[i], nx = N.second + x[i];
if (ny < 0 || nx < 0 || ny > gy || nx > gx || dist[ny][nx] != -1)continue;
else {
dist[ny][nx] = dist[N.first][N.second] + 1;
que.push(make_pair(ny, nx));
}
}
}
if (dist[gy][gx] > 3)cout << "NO" << "\n";
else cout << "YES" << "\n";
return 0;
}
Captain