結果

問題 No.240 ナイト散歩
ユーザー marimom7marimom7
提出日時 2016-01-24 13:32:21
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,005 bytes
コンパイル時間 617 ms
コンパイル使用メモリ 64,544 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-16 19:39:15
合計ジャッジ時間 1,580 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<stdio.h>
#include<iostream>
#include<queue>

using namespace std;

struct P {
	int x = 0;
	int y = 0;
};

int main() {

	int jump = 3;
	int knight = 8;
	int count = jump;
	int knight_jump[8][2] = { {1,2},{2,1},{2,-1},{1,-2},{-1,-2},{-2,-1},{-2,1},{-1,2} };
	bool ans = false;
	queue<P*> q;
	queue<P*> openList;

	P* input_p = new P;
	P* start = new P;

	cin >> input_p->x >> input_p->y;

	openList.push(start);
	q.push(start);
	P* now;
	int open = 0;
	while (count > 0)
	{
		open = q.size();
		for (int i = 0; i < open; i++) {
			now = q.front();
			q.pop();
			for (int i = 0; i < knight; i++) {
				P* point = new P;
				point->x = now->x + knight_jump[i][0];
				point->y = now->y + knight_jump[i][1];
				openList.push(point);
				q.push(point);
			}
		}
		--count;
	}

	while (!openList.empty()) 
	{
		now = openList.front();
		ans |= (now->x == input_p->x && now->y == input_p->y);
		openList.pop();
		delete now;
	}
	
	delete input_p;
	
	cout << (ans ? "YES" : "NO") << endl;

	return 0;
}
0