結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 WA -
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 WA -
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,384 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 2 ms
4,376 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘bool canGoTo(int, int, int&)’ 内:
main.cpp:49:23: 警告: ‘yMin’ may be used uninitialized [-Wmaybe-uninitialized]
   49 |         return canGoTo(xMin,yMin,num);
      |                ~~~~~~~^~~~~~~~~~~~~~~
main.cpp:37:18: 備考: ‘yMin’ はここで定義されています
   37 |         int xMin,yMin;
      |                  ^~~~
main.cpp:49:23: 警告: ‘xMin’ may be used uninitialized [-Wmaybe-uninitialized]
   49 |         return canGoTo(xMin,yMin,num);
      |                ~~~~~~~^~~~~~~~~~~~~~~
main.cpp:37:13: 備考: ‘xMin’ はここで定義されています
   37 |         int xMin,yMin;
      |             ^~~~

ソースコード

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)*(x1-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));
	int i;
	for (i=0;i<myVec.size();i++){
		if (myVec[i].first==X && myVec[i].second==Y){
			myVec.clear();
			cout<<"YES"<<endl;
			return true;
		}
	}
	num++;
	if (num==3){
		cout<<"NO"<<endl;
		return false;
	}
	int xMin,yMin;
	LL distMin=1e18;
	LL distXY;
	for (i=0;i<myVec.size();i++){
		distXY=dist(X,Y,myVec[i].first,myVec[i].second);
		if (distMin>distXY){
			distMin=distXY;
			xMin=myVec[i].first;
			yMin=myVec[i].second;
		}
	}
	myVec.clear();
	return canGoTo(xMin,yMin,num);
}
int main(int argc, char* argv[])
{

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