結果
問題 | No.455 冬の大三角 |
ユーザー |
|
提出日時 | 2022-10-08 20:55:36 |
言語 | Kotlin (2.1.0) |
結果 |
AC
|
実行時間 | 335 ms / 2,000 ms |
コード長 | 1,667 bytes |
コンパイル時間 | 13,042 ms |
コンパイル使用メモリ | 457,512 KB |
実行使用メモリ | 55,908 KB |
最終ジャッジ日時 | 2024-06-22 23:19:50 |
合計ジャッジ時間 | 32,526 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 54 |
ソースコード
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) }