結果

問題 No.48 ロボットの操縦
ユーザー noriocnorioc
提出日時 2015-07-21 03:22:37
言語 Go1.4
(1.4.2)
結果
AC  
実行時間 1 ms / 5,000 ms
コード長 687 bytes
コンパイル時間 282 ms
コンパイル使用メモリ 29,788 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-16 11:56:09
合計ジャッジ時間 1,399 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

package main

import (
	"fmt"
)

// n 進むために必要な移動回数
func advance(n, l int) int {
	d := n / l
	if n%l != 0 {
		d++
	}
	return d
}

func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}

func main() {
	var x, y, l int
	fmt.Scanf("%d %d %d", &x, &y, &l)
	x = abs(x)

	ans := 0
	if y >= 0 {
		ans += advance(y, l)
		if x != 0 {
			ans += advance(x, l)
			ans += 1 // 回転
		}
	} else {
		if x != 0 {
			// x 方向に進む
			ans += 1 // 回転
			ans += advance(x, l)

			if y < 0 {
				ans += 1 // 回転
				ans += advance(-y, l)
			}
		} else {
			// 回転(Y 軸正から負の方向へ)
			ans += 2
			ans += advance(-y, l)
		}
	}

	fmt.Println(ans)
}
0