結果

問題 No.240 ナイト散歩
ユーザー ohreitetsuohreitetsu
提出日時 2018-05-26 17:23:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,746 bytes
コンパイル時間 620 ms
コンパイル使用メモリ 71,284 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-11 03:41:04
合計ジャッジ時間 2,375 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;
typedef long long LL;
int X,Y;
LL dist(int x1,int y1,int x2,int y2){
	return (x1-x2)*(x2-x2)+(y1-y2)*(y1-y2);
}
bool canGoTo(int x,int y,int &num)
{
	if (x==X && y==Y){
		cout<<"YES"<<endl;
		return true;
	}
	vector<pair<int,int>> myVec;
	myVec.push_back(make_pair(x-2,y-1));
	myVec.push_back(make_pair(x-2,y+1));
	myVec.push_back(make_pair(x-1,y-2));
	myVec.push_back(make_pair(x-1,y+2));
	myVec.push_back(make_pair(x+1,y-2));
	myVec.push_back(make_pair(x+1,y+2));
	myVec.push_back(make_pair(x+2,y-1));
	myVec.push_back(make_pair(x+2,y+1));
	for (int i=0;i<myVec.size();i++){
		if (myVec[i].first=X && myVec[i].second==Y){
			myVec.clear();
			cout<<"YES"<<endl;
			return true;
		}
	}
	myVec.clear();
	num++;
	if (num==3){
		cout<<"NO"<<endl;
		return false;
	}
	int xMin,yMin;
	LL distMin=1e18;
	LL distXY;
	distXY=dist(X,Y,x-2,y-1);
	if (distMin>distXY){
		distMin=distXY;
		xMin=x-2;
		yMin=y-1;
	}
	distXY=dist(X,Y,x-2,y+1);
	if (distMin>distXY){
		distMin=distXY;
		xMin=x-2;
		yMin=y+1;
	}
	distXY=dist(X,Y,x-1,y-2);
	if (distMin>distXY){
		distMin=distXY;
		xMin=x-1;
		yMin=y-2;
	}
	distXY=dist(X,Y,x-1,y+2);
	if (distMin>distXY){
		distMin=distXY;
		xMin=x-1;
		yMin=y+2;
	}
	distXY=dist(X,Y,x+1,y-2);
	if (distMin>distXY){
		distMin=distXY;
		xMin=x+1;
		yMin=y-2;
	}
	distXY=dist(X,Y,x+1,y+2);
	if (distMin>distXY){
		distMin=distXY;
		xMin=x+1;
		yMin=y+2;
	}
	distXY=dist(X,Y,x+2,y-1);
	if (distMin>distXY){
		distMin=distXY;
		xMin=x+2;
		yMin=y-1;
	}
	distXY=dist(X,Y,x+2,y+1);
	if (distMin>distXY){
		distMin=distXY;
		xMin=x+2;
		yMin=y+1;
	}
	return canGoTo(xMin,yMin,num);
}
int main(int argc, char* argv[])
{

	cin>>X>>Y;
	int num=1;
	canGoTo(0,0,num);
	return 0;
}
0