結果

問題 No.240 ナイト散歩
ユーザー albicillaalbicilla
提出日時 2015-07-19 01:09:11
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,888 bytes
コンパイル時間 1,298 ms
コンパイル使用メモリ 148,316 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-22 19:05:52
合計ジャッジ時間 4,669 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 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 WA -
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 WA -
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"


using namespace std;

typedef long long ll;
typedef long double ld;


#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define FOR(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end())
#define ub(vec,a) upper_bound(vec.begin(),vec.end())
#define uniq(vec) vec.erace(unique(vec.begin(),vec.end(),vec.end))
#define mp1(a,b,c) P1(a,P(b,c))
#define all(x) (x).begin(),(x).end()

////////////////////
//				  //
// 脳を振り絞れ! //
//				  //
////////////////////
///yukicoder No.240 ナイト散歩
/*概要
ナイトが三回以内に移動できるか
*/
/*方針
行けるマスを記録する。
入力がでかいので気を付ける。
20掛ける20四方考えれば十分

*/

//点の状態
typedef pair<int, int> P;

int x, y;
int sx = 0, sy = 0;
bool field[20][20];
//ナイトの移動のベクトル
int dx[8] = { -2,-2,-1,-1,+1,+1,+2,+2 }, dy[8] = { -1,+1,-2,+2,-2,+2,-1,+1 };

void bfs() {
	queue<P> que;
	//スタート位置を指定
	que.push(P(sx, sy));
	field[sx][sy] = true;
	//三回移動 
	
	while (que.size()) {
		//キューの先頭を取り出す
		P p = que.front();
		que.pop();
		//三回でなく、四回で行けるますのときbreak
		if (p.first <=-8 || p.second <= -4||p.first>=8||p.second>=4)break;
		//移動をループ
		for (int i = 0; i < 8; i++) {
			//移動後の点を(nx,ny)とする
			int nx = p.first + dx[i];
			int ny = p.second + dy[i];
			//移動後の点を格納
			que.push(P(nx, ny));
			field[nx][ny] = true;
		}
	}
}

int main() {
	cin >> x >> y;
	bfs();
	if (field[x][y])cout << "YES" << endl;
	else cout << "NO" << endl;

	return 0;
}
0