結果

問題 No.240 ナイト散歩
ユーザー srup٩(๑`н´๑)۶srup٩(๑`н´๑)۶
提出日時 2016-08-23 21:26:59
言語 C++11
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 703 bytes
コンパイル時間 644 ms
コンパイル使用メモリ 70,300 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-08 00:39:07
合計ジャッジ時間 1,510 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 25 WA * 5
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <queue>
#include <cstdio>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)

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

int main(void){
	int a, b; cin >> a >> b; //X, Y
	queue<pair<int, int> > q;
	queue<int> num;
	q.push(make_pair(0, 0));
	num.push(0);
	while(!q.empty()){
		auto now = q.front(); q.pop();
		auto cnt = num.front(); num.pop();
		if(cnt > 3) continue;
		rep(i, 8){
			int y = now.first + dy[i];
			int x = now.second + dx[i];
			if(y == b && x == a){
				printf("YES\n");
				return 0;
			}
			q.push(make_pair(y, x));
			num.push(cnt + 1);
		}
	}	
	printf("NO\n");
}
0