結果

問題 No.48 ロボットの操縦
ユーザー LeonardoneLeonardone
提出日時 2015-10-11 23:48:51
言語 Ruby
(3.3.0)
結果
AC  
実行時間 89 ms / 5,000 ms
コード長 1,386 bytes
コンパイル時間 40 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 12,288 KB
最終ジャッジ日時 2024-05-01 13:43:03
合計ジャッジ時間 2,974 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 85 ms
12,288 KB
testcase_01 AC 89 ms
12,160 KB
testcase_02 AC 83 ms
12,032 KB
testcase_03 AC 83 ms
12,160 KB
testcase_04 AC 83 ms
12,032 KB
testcase_05 AC 84 ms
12,160 KB
testcase_06 AC 86 ms
12,288 KB
testcase_07 AC 82 ms
12,160 KB
testcase_08 AC 88 ms
12,160 KB
testcase_09 AC 85 ms
12,160 KB
testcase_10 AC 85 ms
12,288 KB
testcase_11 AC 84 ms
12,288 KB
testcase_12 AC 84 ms
12,160 KB
testcase_13 AC 82 ms
12,288 KB
testcase_14 AC 84 ms
12,288 KB
testcase_15 AC 86 ms
12,032 KB
testcase_16 AC 82 ms
12,288 KB
testcase_17 AC 83 ms
12,288 KB
testcase_18 AC 82 ms
12,160 KB
testcase_19 AC 88 ms
12,160 KB
testcase_20 AC 84 ms
12,160 KB
testcase_21 AC 83 ms
12,032 KB
testcase_22 AC 84 ms
12,288 KB
testcase_23 AC 82 ms
12,288 KB
testcase_24 AC 80 ms
12,160 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