結果

問題 No.113 宝探し
ユーザー yo-kondoyo-kondo
提出日時 2018-03-25 19:20:59
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 359 ms / 5,000 ms
コード長 754 bytes
コンパイル時間 13,615 ms
コンパイル使用メモリ 437,544 KB
実行使用メモリ 55,228 KB
最終ジャッジ日時 2024-04-28 08:12:01
合計ジャッジ時間 24,344 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 340 ms
55,000 KB
testcase_01 AC 359 ms
54,776 KB
testcase_02 AC 339 ms
54,680 KB
testcase_03 AC 336 ms
55,060 KB
testcase_04 AC 352 ms
54,784 KB
testcase_05 AC 348 ms
54,904 KB
testcase_06 AC 343 ms
54,716 KB
testcase_07 AC 342 ms
54,676 KB
testcase_08 AC 340 ms
54,824 KB
testcase_09 AC 333 ms
55,064 KB
testcase_10 AC 347 ms
55,044 KB
testcase_11 AC 349 ms
55,132 KB
testcase_12 AC 358 ms
54,772 KB
testcase_13 AC 330 ms
55,016 KB
testcase_14 AC 331 ms
54,824 KB
testcase_15 AC 343 ms
54,916 KB
testcase_16 AC 340 ms
54,612 KB
testcase_17 AC 344 ms
54,668 KB
testcase_18 AC 344 ms
54,604 KB
testcase_19 AC 333 ms
54,684 KB
testcase_20 AC 346 ms
55,000 KB
testcase_21 AC 342 ms
55,124 KB
testcase_22 AC 347 ms
55,220 KB
testcase_23 AC 328 ms
54,872 KB
testcase_24 AC 338 ms
55,228 KB
testcase_25 AC 347 ms
54,720 KB
testcase_26 AC 347 ms
54,816 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:9:10: warning: parameter 'args' is never used
fun main(args: Array<String>) {
         ^

ソースコード

diff #

package yukicoder.no113

import kotlin.math.pow
import kotlin.math.sqrt

/**
 * エントリポイント
 */
fun main(args: Array<String>) {
    val in1 = readLine()
    print(treasureHunt(in1))
}

/**
 * 宝までの最短距離を返します。
 * @param news 方角
 */
fun treasureHunt(news: String?): String {
    if (news == null) {
        return ""
    }

    // [0]:NS, [1]:EW
    val dir = arrayOf(0, 0)
    for (n in news) {
        when (n) {
            'N' -> dir[0]++
            'S' -> dir[0]--
            'E' -> dir[1]++
            'W' -> dir[1]--
        }
    }
    // 南東(NE)
    val ne = dir[0].toDouble().pow(2)
    // 北西(SW)
    val sw = dir[1].toDouble().pow(2)
    return String.format("%.5f", sqrt(ne + sw))
}
0