結果

問題 No.240 ナイト散歩
ユーザー kurenaifkurenaif
提出日時 2016-08-23 21:43:33
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 2,115 bytes
コンパイル時間 850 ms
コンパイル使用メモリ 95,084 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-16 19:43:22
合計ジャッジ時間 1,708 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <queue>
#include <map>
#include <list>
#include <vector>
#include <string>
#include <stack>
#include <limits>
#include <cassert>
#include <fstream>
#include <cstring>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <ciso646>

using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

#define inf 0x3f3f3f3f
#define INF INT_MAX/3
#define PB push_back
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define SET(a,c) memset(a,c,sizeof a)
#define CLR(a) memset(a,0,sizeof a)
#define pii pair<int,int>
#define pcc pair<char,char>
#define pic pair<int,char>
#define pci pair<char,int>
#define VS vector<string>
#define VI vector<int>
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define MIN(a,b) (a>b?b:a)
#define MAX(a,b) (a>b?a:b)
#define pi 2*acos(0.0)
#define INFILE() freopen("in0.txt","r",stdin)
#define OUTFILE()freopen("out0.txt","w",stdout)
#define in scanf
#define out printf
#define ll long long
#define ull unsigned long long
#define eps 1e-14
#define FST first
#define SEC second

int dx[] = { -2,-2,-1,-1,1,1,2,2 };
int dy[] = { -1, 1, -2, 2, -2, 2, -1, 1 };

int field[21][21] = {};

void dfs(ll x,ll y,int depth) {
	if (depth >= 3) return;
	field[x][y] = true;
	for (int i = 0; i < 8; ++i) {
		dfs(x + dx[i], y + dy[i], depth + 1);
	}
}

int main() {
	int X, Y; cin >> X >> Y;
	if (abs(X) >= 10 or abs(Y) >= 10) {
		cout << "NO" << endl;
		return 0;
	}

	memset(field, -1, sizeof(field));
	field[10][10] = 3;
	queue<pii> q;
	q.push({ 10,10 });
	while (not q.empty()) {
		auto p = q.front(); q.pop();
		int x = p.first, y = p.second;
		if (field[y][x] == 0) continue;
		for (int i = 0; i < 8; ++i) {
			int xx = x + dx[i], yy = y + dy[i];
			if (field[yy][xx] == -1 or field[yy][xx] < field[y][x]-1) {
				field[yy][xx] = field[y][x] - 1;
				q.push({ xx ,yy });
			}
		}
	}


	cout << (field[Y+10][X+10] != -1 ? "YES" : "NO") << endl;;
	return 0;
}
0