結果

問題 No.48 ロボットの操縦
ユーザー yo-kondoyo-kondo
提出日時 2018-03-24 21:06:32
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 257 ms / 5,000 ms
コード長 1,278 bytes
コンパイル時間 9,448 ms
コンパイル使用メモリ 430,936 KB
実行使用メモリ 54,488 KB
最終ジャッジ日時 2024-04-30 17:26:28
合計ジャッジ時間 16,659 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 247 ms
54,204 KB
testcase_01 AC 250 ms
54,316 KB
testcase_02 AC 255 ms
54,288 KB
testcase_03 AC 247 ms
54,188 KB
testcase_04 AC 244 ms
54,228 KB
testcase_05 AC 245 ms
54,172 KB
testcase_06 AC 245 ms
54,324 KB
testcase_07 AC 243 ms
54,208 KB
testcase_08 AC 241 ms
54,300 KB
testcase_09 AC 245 ms
54,196 KB
testcase_10 AC 243 ms
54,412 KB
testcase_11 AC 244 ms
54,364 KB
testcase_12 AC 241 ms
54,192 KB
testcase_13 AC 240 ms
54,292 KB
testcase_14 AC 247 ms
54,208 KB
testcase_15 AC 251 ms
54,196 KB
testcase_16 AC 242 ms
54,212 KB
testcase_17 AC 254 ms
54,228 KB
testcase_18 AC 257 ms
54,296 KB
testcase_19 AC 247 ms
54,432 KB
testcase_20 AC 245 ms
54,488 KB
testcase_21 AC 246 ms
54,240 KB
testcase_22 AC 241 ms
54,408 KB
testcase_23 AC 244 ms
54,320 KB
testcase_24 AC 240 ms
54,088 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:10:10: warning: parameter 'args' is never used
fun main(args: Array<String>) {
         ^

ソースコード

diff #

package yukicoder.no48

import kotlin.math.abs
import kotlin.math.ceil

/**
 * エントリポイント
 * @param args コマンドライン引数
 */
fun main(args: Array<String>) {
    val in1 = readLine()
    val in2 = readLine()
    val in3 = readLine()
    println(moveRobot(in1, in2, in3))
}

/**
 * 目的地まで何命令で到達できるかを返します。
 * @param eastWest 目的地の東西方向
 * @param northSouth 目的地の南北方向
 * @param maxDistance ロボットが1命令につき前進することができる最大の距離
 */
fun moveRobot(eastWest: String?, northSouth: String?, maxDistance: String?): String {
    if (eastWest == null || northSouth == null || maxDistance == null) {
        return ""
    }

    var num = 0
    val ew = eastWest.toDouble()
    val ns = northSouth.toDouble()
    val md = maxDistance.toInt()

    // 北
    if (ns > 0) {
        num += ceil(abs(ns / md)).toInt()
    }

    // 東西
    if (ew != 0.0) {
        num++
        num += ceil(abs(ew / md)).toInt()
    }

    // 北から南へ向く場合、いったん東西へ向く
    if (ew == 0.0 && ns < 0) {
        num++
    }

    // 南
    if (ns < 0) {
        num++
        num += ceil(abs(ns / md)).toInt()
    }

    return num.toString()
}
0