結果

問題 No.48 ロボットの操縦
ユーザー yo-kondoyo-kondo
提出日時 2018-03-24 20:56:18
言語 Kotlin
(1.9.23)
結果
WA  
実行時間 -
コード長 1,155 bytes
コンパイル時間 11,669 ms
コンパイル使用メモリ 432,372 KB
実行使用メモリ 54,596 KB
最終ジャッジ日時 2024-04-30 17:24:31
合計ジャッジ時間 16,968 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 251 ms
54,408 KB
testcase_01 AC 249 ms
54,140 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 253 ms
54,200 KB
testcase_05 AC 243 ms
54,340 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 246 ms
54,404 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 240 ms
54,212 KB
testcase_13 WA -
testcase_14 AC 246 ms
54,228 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 261 ms
54,384 KB
testcase_23 WA -
testcase_24 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 += 2
        num += abs(ceil(ns / md).toInt())
    } else if (ns > 0) {
        num += abs(ceil(ns / md).toInt())
    }

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