結果

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

ソースコード

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