結果

問題 No.48 ロボットの操縦
ユーザー eagleeagle
提出日時 2022-06-15 14:58:36
言語 Java21
(openjdk 21)
結果
AC  
実行時間 135 ms / 5,000 ms
コード長 734 bytes
コンパイル時間 2,464 ms
コンパイル使用メモリ 74,792 KB
実行使用メモリ 54,552 KB
最終ジャッジ日時 2024-04-14 23:39:04
合計ジャッジ時間 6,389 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 129 ms
54,064 KB
testcase_01 AC 129 ms
54,036 KB
testcase_02 AC 116 ms
53,056 KB
testcase_03 AC 130 ms
54,356 KB
testcase_04 AC 130 ms
54,392 KB
testcase_05 AC 131 ms
54,092 KB
testcase_06 AC 115 ms
52,916 KB
testcase_07 AC 132 ms
54,176 KB
testcase_08 AC 131 ms
54,244 KB
testcase_09 AC 130 ms
54,116 KB
testcase_10 AC 131 ms
54,216 KB
testcase_11 AC 130 ms
54,076 KB
testcase_12 AC 131 ms
54,116 KB
testcase_13 AC 127 ms
54,176 KB
testcase_14 AC 131 ms
54,284 KB
testcase_15 AC 131 ms
54,016 KB
testcase_16 AC 128 ms
54,076 KB
testcase_17 AC 132 ms
54,156 KB
testcase_18 AC 132 ms
53,952 KB
testcase_19 AC 130 ms
54,248 KB
testcase_20 AC 135 ms
54,552 KB
testcase_21 AC 132 ms
54,120 KB
testcase_22 AC 132 ms
54,276 KB
testcase_23 AC 133 ms
54,208 KB
testcase_24 AC 134 ms
54,056 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		//移動先の東西軸座標
		long X = sc.nextLong();
		//移動先の南北軸座標
		long Y = sc.nextLong();
		//最大移動量
		long L = sc.nextLong();
		//移動回数
		int ans = 0;
		
		if(X < 0) {
			X *= -1;
		}
		if(Y > 0) {
			ans += Y / L;
			if(Y % L != 0) {
				ans++;
			}
		}
		if(X != 0) {
			//方向転換
			ans++;
			ans += X / L;
			if(X % L != 0) {
				ans++;
			}
		}
		if(Y < 0) {
			if(X == 0) {
				ans++;
			}
			ans++;
			Y *= -1;
			ans += Y / L;
			if(Y % L != 0) {
				ans++;
			}
		}
		System.out.println(ans);
	}
}
0