結果

問題 No.240 ナイト散歩
ユーザー fjafjafja
提出日時 2017-09-19 20:18:53
言語 Java
(openjdk 23)
結果
AC  
実行時間 139 ms / 2,000 ms
コード長 1,136 bytes
コンパイル時間 3,475 ms
コンパイル使用メモリ 77,964 KB
実行使用メモリ 41,556 KB
最終ジャッジ日時 2024-11-08 05:45:20
合計ジャッジ時間 9,344 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

package yukicoder;

import java.util.Scanner;

public class N240
{
	static int x,y,nowx=0,nowy=0,end=0,bufx=0,bufy=0,bufbufx=0,bufbufy=0;
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		x=sc.nextInt();y=sc.nextInt();
		check();
		for(int i=0;end==0&&i<=7;i++)
		{	nowx=0;nowy=0;
			move(i);
			check();
			bufx=nowx;bufy=nowy;
			for(int j=0;end==0&&j<=7;j++)
			{
				nowx=bufx;nowy=bufy;
				move(j);
				check();
				bufbufx=nowx;bufbufy=nowy;
				for(int k=0;end==0&&k<=7;k++)
				{
					nowx=bufbufx;nowy=bufbufy;
					move(k);
					check();
				}
			}
		}
		if(end==1){System.out.println("YES");}
		else{System.out.println("NO");}
	}

	static void check()
	{
		if(x==nowx&&y==nowy){end=1;return;}
		else {return ;}
	}


	static void move(int i)
	{
		switch(i)
		{
		case 0:
			nowx+=2;nowy+=1;
			break;
		case 1:
			nowx+=2;nowy-=1;
			break;
		case 2:
			nowx-=2;nowy+=1;
			break;
		case 3:
			nowx-=2;nowy-=1;
			break;
		case 4:
			nowx+=1;nowy+=2;
			break;
		case 5:
			nowx+=1;nowy-=2;
			break;
		case 6:
			nowx-=1;nowy+=2;
			break;
		case 7:
			nowx-=1;nowy-=2;
			break;
		}
	}

}
0