結果

問題 No.48 ロボットの操縦
ユーザー CavasiroCavasiro
提出日時 2020-04-16 22:42:12
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 1,104 bytes
コンパイル時間 2,265 ms
コンパイル使用メモリ 77,432 KB
実行使用メモリ 61,028 KB
最終ジャッジ日時 2024-04-10 11:58:58
合計ジャッジ時間 9,040 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 113 ms
54,212 KB
testcase_01 AC 94 ms
52,964 KB
testcase_02 AC 98 ms
53,048 KB
testcase_03 TLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
権限があれば一括ダウンロードができます

ソースコード

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(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(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