結果

問題 No.457 (^^*)
ユーザー qszhuqszhu
提出日時 2022-10-09 17:32:14
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 342 ms / 2,000 ms
コード長 1,715 bytes
コンパイル時間 19,381 ms
コンパイル使用メモリ 428,380 KB
実行使用メモリ 59,096 KB
最終ジャッジ日時 2023-09-05 21:11:08
合計ジャッジ時間 25,134 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 315 ms
57,484 KB
testcase_01 AC 313 ms
56,688 KB
testcase_02 AC 312 ms
56,912 KB
testcase_03 AC 313 ms
57,248 KB
testcase_04 AC 312 ms
58,928 KB
testcase_05 AC 319 ms
58,680 KB
testcase_06 AC 314 ms
57,116 KB
testcase_07 AC 308 ms
58,776 KB
testcase_08 AC 308 ms
57,052 KB
testcase_09 AC 313 ms
56,728 KB
testcase_10 AC 321 ms
58,916 KB
testcase_11 AC 316 ms
58,612 KB
testcase_12 AC 342 ms
58,936 KB
testcase_13 AC 311 ms
58,572 KB
testcase_14 AC 315 ms
58,456 KB
testcase_15 AC 317 ms
58,980 KB
testcase_16 AC 312 ms
59,096 KB
testcase_17 AC 313 ms
58,484 KB
testcase_18 AC 312 ms
58,940 KB
testcase_19 AC 315 ms
58,596 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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(" "))
0