結果
| 問題 | No.707 書道 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-08-19 13:29:34 |
| 言語 | Kotlin (2.3.20) |
| 結果 |
AC
|
| 実行時間 | 233 ms / 2,000 ms |
| コード長 | 1,910 bytes |
| 記録 | |
| コンパイル時間 | 10,193 ms |
| コンパイル使用メモリ | 478,068 KB |
| 実行使用メモリ | 54,668 KB |
| 最終ジャッジ日時 | 2026-05-14 19:40:04 |
| 合計ジャッジ時間 | 12,388 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 6 |
ソースコード
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())
}