結果

問題 No.455 冬の大三角
ユーザー qszhuqszhu
提出日時 2022-10-08 20:10:16
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 358 ms / 2,000 ms
コード長 2,072 bytes
コンパイル時間 17,093 ms
コンパイル使用メモリ 428,168 KB
実行使用メモリ 59,448 KB
最終ジャッジ日時 2023-09-05 01:44:01
合計ジャッジ時間 40,831 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 318 ms
57,392 KB
testcase_01 AC 319 ms
59,280 KB
testcase_02 AC 322 ms
58,980 KB
testcase_03 AC 329 ms
58,988 KB
testcase_04 AC 334 ms
58,964 KB
testcase_05 AC 329 ms
58,952 KB
testcase_06 AC 323 ms
57,396 KB
testcase_07 AC 328 ms
59,128 KB
testcase_08 AC 354 ms
57,320 KB
testcase_09 AC 324 ms
57,220 KB
testcase_10 AC 326 ms
57,088 KB
testcase_11 AC 332 ms
57,200 KB
testcase_12 AC 332 ms
59,308 KB
testcase_13 AC 329 ms
57,084 KB
testcase_14 AC 329 ms
57,072 KB
testcase_15 AC 329 ms
58,868 KB
testcase_16 AC 328 ms
56,992 KB
testcase_17 AC 321 ms
57,116 KB
testcase_18 AC 326 ms
58,824 KB
testcase_19 AC 323 ms
57,096 KB
testcase_20 AC 318 ms
59,212 KB
testcase_21 AC 327 ms
59,116 KB
testcase_22 AC 329 ms
59,064 KB
testcase_23 AC 323 ms
59,112 KB
testcase_24 AC 332 ms
59,328 KB
testcase_25 AC 329 ms
57,440 KB
testcase_26 AC 324 ms
57,416 KB
testcase_27 AC 328 ms
57,252 KB
testcase_28 AC 327 ms
58,824 KB
testcase_29 AC 350 ms
59,044 KB
testcase_30 AC 334 ms
57,532 KB
testcase_31 AC 345 ms
59,388 KB
testcase_32 AC 334 ms
57,160 KB
testcase_33 AC 358 ms
59,308 KB
testcase_34 AC 337 ms
59,312 KB
testcase_35 AC 355 ms
57,676 KB
testcase_36 AC 342 ms
59,436 KB
testcase_37 AC 326 ms
57,484 KB
testcase_38 AC 341 ms
59,148 KB
testcase_39 AC 353 ms
57,464 KB
testcase_40 AC 349 ms
59,448 KB
testcase_41 AC 337 ms
59,060 KB
testcase_42 AC 331 ms
57,428 KB
testcase_43 AC 329 ms
57,164 KB
testcase_44 AC 327 ms
57,376 KB
testcase_45 AC 357 ms
59,120 KB
testcase_46 AC 342 ms
59,048 KB
testcase_47 AC 341 ms
59,196 KB
testcase_48 AC 336 ms
57,264 KB
testcase_49 AC 330 ms
58,824 KB
testcase_50 AC 334 ms
59,068 KB
testcase_51 AC 335 ms
57,508 KB
testcase_52 AC 334 ms
57,408 KB
testcase_53 AC 335 ms
57,236 KB
testcase_54 AC 333 ms
59,356 KB
testcase_55 AC 335 ms
58,964 KB
testcase_56 AC 333 ms
59,008 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import kotlin.random.Random
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))
}

fun solve(H: Int, W: Int, S: Array<CharArray>): Array<CharArray> {
    while (true) {
        val r = Random.nextInt(H)
        val c = Random.nextInt(W)
        if (S[r][c] == '*') continue

        var sameCol = 0
        for (r0 in 0 until H) {
            if (S[r0][c] == '*') sameCol++
        }
        if (sameCol > 1) continue

        var sameRow = 0
        for (c0 in 0 until W) {
            if (S[r][c0] == '*') sameRow++
        }
        if (sameRow > 1) continue

        var sameDiag = 0
        var r0 = r
        var c0 = c
        while (r0 >= 0 && c0 >= 0) {
            if (S[r0][c0] == '*') sameDiag++
            r0--
            c0--
        }
        r0 = r
        c0 = c
        while (r0 < H && c0 < W) {
            if (S[r0][c0] == '*') sameDiag++
            r0++
            c0++
        }
        if (sameDiag > 1) continue

        sameDiag = 0
        r0 = r
        c0 = c
        while (r0 >= 0 && c0 < W) {
            if (S[r0][c0] == '*') sameDiag++
            r0--
            c0++
        }
        r0 = r
        c0 = c
        while (r0 < H && c0 >= 0) {
            if (S[r0][c0] == '*') sameDiag++
            r0++
            c0--
        }
        if (sameDiag > 1) continue

        S[r][c] = '*'
        return S
    }
}

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