結果

問題 No.48 ロボットの操縦
ユーザー LeonardoneLeonardone
提出日時 2015-10-11 23:48:51
言語 Ruby
(3.3.0)
結果
AC  
実行時間 82 ms / 5,000 ms
コード長 1,386 bytes
コンパイル時間 279 ms
コンパイル使用メモリ 11,320 KB
実行使用メモリ 15,368 KB
最終ジャッジ日時 2023-08-14 00:15:27
合計ジャッジ時間 3,931 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 82 ms
15,216 KB
testcase_01 AC 80 ms
15,152 KB
testcase_02 AC 81 ms
15,148 KB
testcase_03 AC 82 ms
15,280 KB
testcase_04 AC 80 ms
15,152 KB
testcase_05 AC 82 ms
15,280 KB
testcase_06 AC 80 ms
15,260 KB
testcase_07 AC 79 ms
15,044 KB
testcase_08 AC 81 ms
15,128 KB
testcase_09 AC 79 ms
15,336 KB
testcase_10 AC 81 ms
15,140 KB
testcase_11 AC 79 ms
15,128 KB
testcase_12 AC 80 ms
15,240 KB
testcase_13 AC 81 ms
15,220 KB
testcase_14 AC 80 ms
15,148 KB
testcase_15 AC 81 ms
15,224 KB
testcase_16 AC 78 ms
15,368 KB
testcase_17 AC 79 ms
15,124 KB
testcase_18 AC 79 ms
15,056 KB
testcase_19 AC 80 ms
15,300 KB
testcase_20 AC 81 ms
15,040 KB
testcase_21 AC 78 ms
15,180 KB
testcase_22 AC 77 ms
15,236 KB
testcase_23 AC 80 ms
15,048 KB
testcase_24 AC 80 ms
15,136 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

#! ruby

X = gets.to_i
Y = gets.to_i
L = gets.to_i

# 頭の中を整理するためメモ

# 目的地が原点のとき
#    方向転換も移動も不要
if X == 0 && Y == 0
    puts "0"

# 目的地がY軸上(X=0)のとき、横移動は必要ない
#    目的地が北(Y>0)のとき
#           方向転換は必要ない
#           ceil(Y / L) 回の移動
#    目的地が南(Y<0)のとき
#           2回方向転換が必要
#           ceil(abs(Y) / L) 回の移動
elsif X == 0
    if Y > 0
        puts (Y.to_f / L.to_f).ceil
    else
        puts (2 + (Y.abs.to_f / L.to_f).ceil)
    end

# 目的地がX軸上(Y=0)のとき、縦移動は必要ない
#           1回方向転換が必要
#           ceil(abs(X) / L) 回の移動
elsif Y == 0
    puts (1 + (X.abs.to_f / L.to_f).ceil)

# 上記以外のケース
#     目的地が北側(Y>0)にあるとき
#          北に ceil(Y/L) 回移動
#          1回方向転換で横向きに
#           ceil(abs(X)/L)回移動
#    目的地が南側(Y<0)にあるとき
#           1回方向転換して横向きに
#           ceil(abs(X)/L)回移動
#           1回方向転換して南向きに
#           ceil(abs(Y)/L)回移動
else
    if Y > 0
        puts ((Y.to_f/L.to_f).ceil + 1 + (X.abs.to_f/L.to_f).ceil)
    else
        puts (1 + (X.abs.to_f/L.to_f).ceil + 1 + (Y.abs.to_f/L.to_f).ceil)
    end
end
0