結果

問題 No.48 ロボットの操縦
ユーザー korogy
提出日時 2017-09-08 00:14:44
言語 Ruby
(3.4.1)
結果
AC  
実行時間 87 ms / 5,000 ms
コード長 983 bytes
コンパイル時間 92 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 12,288 KB
最終ジャッジ日時 2024-11-07 11:52:47
合計ジャッジ時間 3,153 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 25
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

class PilotRobot
    attr_reader :x, :y, :l

    def initialize(x: 0, y: 0, l: 0)
        @x, @y, @l = x, y, l
    end

    def datainput
        begin
            @x = Integer(gets.chomp)
            @y = Integer(gets.chomp)
            @l = Integer(gets.chomp)
        rescue
            
        end
    end

    def pilot(x, y, l)
        return 0 if x == 0 and y == 0

        action = 0

        # y方向の移動
        action += y.abs / l
        action += 1 if (y.abs % l) != 0
        
        # x方向の移動
        action += x.abs / l
        action += 1 if (x.abs % l) != 0
        
        # x方向の回転
        action += 1 if x != 0
        
        # y方向の回転
        if y < 0
          action += 1
          action += 1 if x == 0
        end
        
        return action
    end

    def dataoutput
        puts pilot(@x, @y, @l)
    end

    def run
        datainput
        dataoutput
    end
end

if $0 == __FILE__
    PilotRobot.new.run
end
0