結果

問題 No.707 書道
ユーザー Pump0129Pump0129
提出日時 2018-08-19 13:29:34
言語 Kotlin
(1.9.10)
結果
AC  
実行時間 348 ms / 2,000 ms
コード長 1,910 bytes
コンパイル時間 15,054 ms
コンパイル使用メモリ 430,912 KB
実行使用メモリ 53,644 KB
最終ジャッジ日時 2023-08-13 00:16:10
合計ジャッジ時間 18,942 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 298 ms
52,964 KB
testcase_01 AC 298 ms
52,964 KB
testcase_02 AC 318 ms
53,016 KB
testcase_03 AC 293 ms
53,004 KB
testcase_04 AC 295 ms
52,920 KB
testcase_05 AC 346 ms
53,412 KB
testcase_06 AC 347 ms
53,644 KB
testcase_07 AC 348 ms
53,428 KB
testcase_08 AC 301 ms
53,036 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:17:10: warning: parameter 'args' is never used
fun main(args: Array<String>) {
         ^

ソースコード

diff #

package net.ipipip0129.kotlin.yukicoder

import kotlin.math.sqrt

fun checkCorner(w: Int, h: Int, sizeW: Int, sizeH: Int): Boolean {
    val checkPos = arrayOf(arrayOf(0, 0), arrayOf(0, sizeW + 1), arrayOf(sizeH + 1, 0), arrayOf(sizeH + 1, sizeW + 1))
    checkPos.forEach {
        if (it[0] == h && it[1] == w) {
            return true
        }
    }
    return false
}

fun Int.square(): Int = this * this

fun main(args: Array<String>) {
    val sizeSplit = readLine()!!.split(" ")
    val sizeH = sizeSplit[0].toInt()
    val sizeW = sizeSplit[1].toInt()
    val tailMap = Array(sizeH + 2, { Array(sizeW + 2, { 0 }) })
    val checkRange = { index: Int, size: Int -> index == 0 || index == size + 1 }
    tailMap.forEachIndexed { indexH, ints ->
        ints.forEachIndexed { indexW, _ ->
            if (checkRange(indexW, sizeW) || checkRange(indexH, sizeH)) {
                if (!checkCorner(indexW, indexH, sizeW, sizeH)) {
                    tailMap[indexH][indexW] = 2
                }
            }
        }
    }
    for (i in 0 until sizeH) {
        readLine()!!.toCharArray().forEachIndexed { index, c ->
            tailMap[i + 1][index + 1] = c.toString().toInt()
        }
    }

    val blackPos = mutableListOf<Array<Int>>()
    val standPos = mutableListOf<Array<Int>>()

    tailMap.forEachIndexed { indexH, ints ->
        ints.forEachIndexed { indexW, i ->
            when (i) {
                1 -> blackPos.add(arrayOf(indexH, indexW))
                2 -> standPos.add(arrayOf(indexH, indexW))
            }
        }
    }

    val timeList = mutableListOf<Double>()

    standPos.forEach { pos ->
        var time = 0.0
        blackPos.forEach {
            time += sqrt(((pos[0] - it[0]).square() + (pos[1] - it[1]).square()).toDouble())
        }
        timeList.add(time)
    }
    println(timeList.min())
}
0