結果

問題 No.48 ロボットの操縦
ユーザー CavasiroCavasiro
提出日時 2020-04-16 22:46:17
言語 Java21
(openjdk 21)
結果
AC  
実行時間 3,300 ms / 5,000 ms
コード長 1,124 bytes
コンパイル時間 2,288 ms
コンパイル使用メモリ 77,956 KB
実行使用メモリ 54,352 KB
最終ジャッジ日時 2024-04-10 12:12:01
合計ジャッジ時間 9,816 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 135 ms
54,088 KB
testcase_01 AC 135 ms
54,120 KB
testcase_02 AC 136 ms
54,148 KB
testcase_03 AC 3,300 ms
54,164 KB
testcase_04 AC 131 ms
54,196 KB
testcase_05 AC 132 ms
53,920 KB
testcase_06 AC 133 ms
53,992 KB
testcase_07 AC 141 ms
54,108 KB
testcase_08 AC 142 ms
54,032 KB
testcase_09 AC 140 ms
54,108 KB
testcase_10 AC 136 ms
54,120 KB
testcase_11 AC 138 ms
54,108 KB
testcase_12 AC 140 ms
54,096 KB
testcase_13 AC 137 ms
54,160 KB
testcase_14 AC 136 ms
53,864 KB
testcase_15 AC 140 ms
54,352 KB
testcase_16 AC 136 ms
54,164 KB
testcase_17 AC 136 ms
53,904 KB
testcase_18 AC 139 ms
54,324 KB
testcase_19 AC 137 ms
53,768 KB
testcase_20 AC 132 ms
54,272 KB
testcase_21 AC 134 ms
54,112 KB
testcase_22 AC 133 ms
54,000 KB
testcase_23 AC 134 ms
53,996 KB
testcase_24 AC 132 ms
54,244 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;
 
class Main {
	int x;
	int y;
	int l;
	int cnt;
	int ix;
	int iy;
	int f;
	int[][] face = {{0,1},{1,0},{0,-1},{-1,0}};

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int y = sc.nextInt();
		int l = sc.nextInt();
		Main m = new Main(x,y,l);
		System.out.println(m.start());
	}
	Main(int x,int y,int l){
		this.x = x;
		this.y = y;
		this.l = l;
		cnt = 0;
		ix = 0;
		iy = 0;
		f = 0;
	}
	int start(){
		if(y>=0){
			while(iy+l<y){
				iy += face[f][1]*l;
				cnt++;
			}
			if(iy!=y){
				cnt++;
			}
			iy = y;
		}
		if(x>0){
			turn(1);
		} else if(x<0){
			turn(-1);
		}
		while(Math.abs(ix)+l<Math.abs(x)){
			ix += face[f][0]*l;
			cnt++;
		}
		if(ix!=x){
			cnt++;
		}
		ix = x;
		if(y<0){
			if(f==0){
				turn(1);
				turn(1);
			} else {
				turn(2-f);
			}
		}
		while(Math.abs(iy)+l<Math.abs(y)){
			iy += face[f][1]*l;
			cnt++;
		}
		if(iy!=y){
			cnt++;
		}
		iy = y;
		return cnt;
	}
	void turn(int flag){
		cnt++;
		if(flag>=0){
			f++;
			if(f>3){
				f = 0;
			}
		} else {
			f--;
			if(f<0){
				f = 3;
			}
		}
	}
}
0