結果

問題 No.240 ナイト散歩
ユーザー CaptainCaptain
提出日時 2019-10-20 00:24:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 913 bytes
コンパイル時間 1,630 ms
コンパイル使用メモリ 174,440 KB
実行使用メモリ 11,456 KB
最終ジャッジ日時 2023-09-10 11:23:54
合計ジャッジ時間 9,665 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 AC 2 ms
4,380 KB
testcase_03 RE -
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 RE -
testcase_08 RE -
testcase_09 TLE -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0