結果

問題 No.240 ナイト散歩
コンテスト
ユーザー suppy193
提出日時 2015-07-13 15:54:37
言語 C(gnu17)
(gcc 15.2.0)
コンパイル:
gcc-15 -O2 -std=gnu17 -Wno-error=implicit-function-declaration -Wno-error=implicit-int -Wno-error=incompatible-pointer-types -Wno-error=int-conversion -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,279 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 133 ms
コンパイル使用メモリ 38,868 KB
最終ジャッジ日時 2026-02-23 18:42:48
ジャッジサーバーID
(参考情報)
judge2 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function 'dfs':
main.c:3:5: warning: type of 'x0' defaults to 'int' [-Wimplicit-int]
    3 | int dfs(x0, y0, x, y, n)
      |     ^~~
main.c:3:5: warning: type of 'y0' defaults to 'int' [-Wimplicit-int]
main.c:3:5: warning: type of 'x' defaults to 'int' [-Wimplicit-int]
main.c:3:5: warning: type of 'y' defaults to 'int' [-Wimplicit-int]
main.c:3:5: warning: type of 'n' defaults to 'int' [-Wimplicit-int]

ソースコード

diff #
raw source code

#include <stdio.h>

int dfs(x0, y0, x, y, n)
{
	//printf("%d,%d\n", x0, y0);
	if(n <= 0){
		return 0;
	}
	if(x0 == x && y0 == y){
		return 1;
	}
	if(x0 - 2 == x && y0 - 1 == y){
		return 1;
		
	}
	else if(dfs(x0 - 2, y0 - 1, x, y, n - 1) == 1){
		return 1;
	}
	if(x0 - 2 == x && y0 + 1 == y){
		return 1;
		
	}
	else if(dfs(x0 - 2, y0 + 1, x, y, n - 1) == 1){
		return 1;
	}
	if(x0 - 1 == x && y0 - 2 == y){
		return 1;
		
	}
	else if(dfs(x0 - 1, y0 - 2, x, y, n - 1) == 1){
		return 1;
	}
	if(x0 - 1 == x && y0 + 2 == y){
		return 1;
		
	}
	else if(dfs(x0 - 1, y0 + 2, x, y, n - 1) == 1){
		return 1;
	}
	if(x0 + 1 == x && y0 - 2 == y){
		return 1;
		
	}
	else if(dfs(x0 + 1, y0 - 2, x, y, n - 1) == 1){
		return 1;
	}
	if(x0 + 1 == x && y0 + 2 == y){
		return 1;
		
	}
	else if(dfs(x0 + 1, y0 + 2, x, y, n - 1) == 1){
		return 1;
	}
	if(x0 + 2 == x && y0 - 1 == y){
		return 1;
		
	}
	else if(dfs(x0 + 2, y0 - 1, x, y, n - 1) == 1){
		return 1;
	}
	if(x0 + 2 == x && y0 + 1 == y){
		return 1;
		
	}
	else if(dfs(x0 + 2, y0 + 1, x, y, n - 1) == 1){
		return 1;
	}
	
	//,(x+2,y-1),(x+2,y+1)
	
}

int main(void) {
	int x, y;
	int x0, y0;
	scanf("%d%d", &x, &y);
	x0 = 0;
	y0 = 0;
	
	if(dfs(x0, y0, x, y, 3) == 1){
		printf("YES\n");
	}
	else{
		printf("NO\n");
	}

    return 0;
}
0