結果

問題 No.707 書道
ユーザー Pump0129Pump0129
提出日時 2018-08-19 13:29:34
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 331 ms / 2,000 ms
コード長 1,910 bytes
コンパイル時間 12,434 ms
コンパイル使用メモリ 454,936 KB
実行使用メモリ 57,576 KB
最終ジャッジ日時 2024-04-30 19:08:07
合計ジャッジ時間 16,530 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 293 ms
57,168 KB
testcase_01 AC 279 ms
56,952 KB
testcase_02 AC 288 ms
57,068 KB
testcase_03 AC 270 ms
56,932 KB
testcase_04 AC 282 ms
57,116 KB
testcase_05 AC 313 ms
57,468 KB
testcase_06 AC 312 ms
57,576 KB
testcase_07 AC 331 ms
57,504 KB
testcase_08 AC 284 ms
56,932 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