結果

問題 No.240 ナイト散歩
ユーザー srup٩(๑`н´๑)۶srup٩(๑`н´๑)۶
提出日時 2016-08-23 21:26:30
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 703 bytes
コンパイル時間 639 ms
コンパイル使用メモリ 70,384 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-25 13:40:30
合計ジャッジ時間 1,628 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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