結果

問題 No.455 冬の大三角
ユーザー qszhuqszhu
提出日時 2022-10-08 20:55:36
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 340 ms / 2,000 ms
コード長 1,667 bytes
コンパイル時間 18,485 ms
コンパイル使用メモリ 426,660 KB
実行使用メモリ 61,080 KB
最終ジャッジ日時 2023-09-05 02:28:27
合計ジャッジ時間 38,931 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 320 ms
59,252 KB
testcase_01 AC 312 ms
59,268 KB
testcase_02 AC 316 ms
57,804 KB
testcase_03 AC 315 ms
57,660 KB
testcase_04 AC 313 ms
59,364 KB
testcase_05 AC 312 ms
57,516 KB
testcase_06 AC 316 ms
59,248 KB
testcase_07 AC 315 ms
57,372 KB
testcase_08 AC 340 ms
57,460 KB
testcase_09 AC 314 ms
59,360 KB
testcase_10 AC 319 ms
59,316 KB
testcase_11 AC 314 ms
57,288 KB
testcase_12 AC 313 ms
57,416 KB
testcase_13 AC 315 ms
59,252 KB
testcase_14 AC 316 ms
59,572 KB
testcase_15 AC 316 ms
59,344 KB
testcase_16 AC 316 ms
57,304 KB
testcase_17 AC 319 ms
57,512 KB
testcase_18 AC 317 ms
59,172 KB
testcase_19 AC 313 ms
59,144 KB
testcase_20 AC 319 ms
59,148 KB
testcase_21 AC 318 ms
57,260 KB
testcase_22 AC 319 ms
57,416 KB
testcase_23 AC 314 ms
59,144 KB
testcase_24 AC 316 ms
57,400 KB
testcase_25 AC 315 ms
57,276 KB
testcase_26 AC 316 ms
57,484 KB
testcase_27 AC 315 ms
57,784 KB
testcase_28 AC 309 ms
59,188 KB
testcase_29 AC 337 ms
59,408 KB
testcase_30 AC 322 ms
57,500 KB
testcase_31 AC 315 ms
59,560 KB
testcase_32 AC 315 ms
59,484 KB
testcase_33 AC 335 ms
59,384 KB
testcase_34 AC 320 ms
57,576 KB
testcase_35 AC 334 ms
57,508 KB
testcase_36 AC 324 ms
57,552 KB
testcase_37 AC 316 ms
61,080 KB
testcase_38 AC 316 ms
59,344 KB
testcase_39 AC 338 ms
57,388 KB
testcase_40 AC 334 ms
59,416 KB
testcase_41 AC 319 ms
57,396 KB
testcase_42 AC 315 ms
59,328 KB
testcase_43 AC 312 ms
59,288 KB
testcase_44 AC 321 ms
59,360 KB
testcase_45 AC 332 ms
59,344 KB
testcase_46 AC 325 ms
59,256 KB
testcase_47 AC 321 ms
57,660 KB
testcase_48 AC 316 ms
57,856 KB
testcase_49 AC 311 ms
59,552 KB
testcase_50 AC 313 ms
59,244 KB
testcase_51 AC 316 ms
57,684 KB
testcase_52 AC 319 ms
59,404 KB
testcase_53 AC 316 ms
57,616 KB
testcase_54 AC 315 ms
57,392 KB
testcase_55 AC 320 ms
57,276 KB
testcase_56 AC 316 ms
59,144 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import kotlin.system.exitProcess

val br = System.`in`.bufferedReader()

fun readLine(): String? = br.readLine()
fun readString() = readLine()!!
fun readStrings() = readLine()?.split(" ")?.filter { it.isNotEmpty() } ?: listOf()
fun readInts() = readStrings().map { it.toInt() }.toIntArray()

const val MAX_STACK_SIZE: Long = 128 * 1024 * 1024

fun main() {
    val thread = Thread(null, ::run, "solve", MAX_STACK_SIZE)
    thread.setUncaughtExceptionHandler { _, e -> e.printStackTrace(); exitProcess(1) }
    thread.start()
}

fun run() {
    val (H, W) = readInts()
    val S = Array(H) { readString().toCharArray() }
    output(solve(H, W, S))
}

typealias Vector2 = Pair<Int, Int>

operator fun Vector2.minus(other: Vector2): Vector2 {
    val (x1, y1) = this
    val (x2, y2) = other
    return Vector2(x1 - x2, y1 - y2)
}

infix fun Vector2.cross(other: Vector2): Int {
    val (x1, y1) = this
    val (x2, y2) = other
    return x1 * y2 - y1 * x2
}

fun solve(H: Int, W: Int, S: Array<CharArray>): Array<CharArray> {
    val rows = H
    val cols = W
    val stars = mutableListOf<Pair<Int, Int>>()
    for (r in 0 until rows) {
        for (c in 0 until cols) {
            if (S[r][c] == '*') stars.add(r to c)
        }
    }
    for (r in 0 until rows) {
        for (c in 0 until cols) {
            if (S[r][c] == '*') continue
            val a = stars[1] - stars[0]
            val b = Vector2(r, c) - stars[0]
            if (a cross b == 0) continue
            S[r][c] = '*'
            return S
        }
    }

    return S
}

fun output(res: Array<CharArray>) =
    res.joinToString("\n") { it.joinToString("") }
        .apply { println(this) }
0