結果
問題 | No.457 (^^*) |
ユーザー |
|
提出日時 | 2022-10-09 17:32:14 |
言語 | Kotlin (2.1.0) |
結果 |
AC
|
実行時間 | 330 ms / 2,000 ms |
コード長 | 1,715 bytes |
コンパイル時間 | 16,562 ms |
コンパイル使用メモリ | 463,956 KB |
実行使用メモリ | 62,664 KB |
最終ジャッジ日時 | 2024-06-23 16:33:44 |
合計ジャッジ時間 | 21,262 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 20 |
ソースコード
import kotlin.system.exitProcess val br = System.`in`.bufferedReader() fun readLine(): String? = br.readLine() fun readString() = readLine()!! fun readInt() = readString().toInt() fun readLong() = readString().toLong() fun readDouble() = readString().toDouble() fun readStrings() = readLine()?.split(" ")?.filter { it.isNotEmpty() } ?: listOf() fun readInts() = readStrings().map { it.toInt() }.toIntArray() fun readLongs() = readStrings().map { it.toLong() }.toLongArray() fun readDoubles() = readStrings().map { it.toDouble() }.toDoubleArray() fun readLines(n: Int) = Array(n) { readString() } 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 S = readString() output(solve(S)) } fun solve(S: String): Pair<Int, Int> { // 01234 // L: (^^*) // R: (*^^) val dpL = IntArray(5) val dpR = IntArray(5) for (c in S) { when (c) { '(' -> { dpL[0]++ dpR[0]++ } '^' -> { dpL[2] += dpL[1].also { dpL[1] = dpL[0] }.also { dpL[0] = 0 } dpR[3] += dpR[2].also { dpR[2] = dpR[1] }.also { dpR[1] = 0 } } '*' -> { dpL[3] += dpL[2].also { dpL[2] = 0 } dpR[1] += dpR[0].also { dpR[0] = 0 } } ')' -> { dpL[4] += dpL[3] dpR[4] += dpR[3] } } } return dpL[4] to dpR[4] } fun output(res: Pair<Int, Int>) = println(res.toList().joinToString(" "))