結果

問題 No.48 ロボットの操縦
ユーザー sjgq5302sjgq5302
提出日時 2017-08-22 23:56:46
言語 Ruby
(3.3.0)
結果
TLE  
実行時間 -
コード長 1,209 bytes
コンパイル時間 61 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 19,360 KB
最終ジャッジ日時 2024-04-23 04:50:42
合計ジャッジ時間 7,052 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 82 ms
12,288 KB
testcase_01 AC 83 ms
12,288 KB
testcase_02 AC 82 ms
12,416 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 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

input = []
while line = gets     #入力のEOF(nil)に達するまで各行を読み込んでline変数に代入するwhile処理
    line.chomp!       
    input << line.to_i
end

x = input[0] #ゴールX座標
y = input[1] #ゴールY座標
move = input[2] #移動可能距離
zahyou = [0, 0] #現在の座標
command = 0

if y > 0 then #Y方向へ先に移動する
    while zahyou[1] < y do
        zahyou[1] += move
        command += 1
    end
    
    if x != 0 then
        command += 1 #向きを変える
        
        while zahyou[0] < x.abs do
            zahyou[0] += move
            command += 1
        end
    end
elsif y < 0 then #X方向へ先に移動する
    
    command += 1 #向きを変える
    
    if x != 0
        while zahyou[0] < x.abs do
            zahyou[0] += move
            command += 1
        end
    end
    
    command += 1 #向きを変える
    
    while zahyou[1] < y.abs do
        zahyou[1] += move
        command += 1
    end
else #Y方向への移動が0の時
    if x != 0
        command += 1 #向きを変える
    
        while zahyou[0] < x.abs do
            zahyou[0] += move
            command += 1
        end
    end
end

puts command
0