結果

問題 No.22 括弧の対応
ユーザー バカらっくバカらっく
提出日時 2019-09-02 00:27:28
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 318 ms / 5,000 ms
コード長 691 bytes
コンパイル時間 14,723 ms
コンパイル使用メモリ 423,208 KB
実行使用メモリ 53,568 KB
最終ジャッジ日時 2023-09-27 13:42:24
合計ジャッジ時間 19,093 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 258 ms
52,928 KB
testcase_01 AC 256 ms
52,912 KB
testcase_02 AC 253 ms
53,000 KB
testcase_03 AC 318 ms
53,368 KB
testcase_04 AC 274 ms
53,104 KB
testcase_05 AC 271 ms
52,880 KB
testcase_06 AC 281 ms
53,132 KB
testcase_07 AC 285 ms
53,208 KB
testcase_08 AC 279 ms
53,008 KB
testcase_09 AC 264 ms
52,928 KB
testcase_10 AC 285 ms
53,124 KB
testcase_11 AC 271 ms
52,916 KB
testcase_12 AC 285 ms
53,068 KB
testcase_13 AC 281 ms
53,088 KB
testcase_14 AC 260 ms
52,980 KB
testcase_15 AC 291 ms
53,236 KB
testcase_16 AC 289 ms
53,568 KB
testcase_17 AC 255 ms
52,796 KB
testcase_18 AC 265 ms
52,904 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:1:10: warning: parameter 'args' is never used
fun main(args: Array<String>) {
         ^
Main.kt:2:10: warning: variable 'n' is never used
    val (n,k) = readLine()!!.split(" ").map { it.toInt() }
         ^

ソースコード

diff #

fun main(args: Array<String>) {
    val (n,k) = readLine()!!.split(" ").map { it.toInt() }
    val s = readLine()!!
    val list = mutableListOf<Kakko>()
    s.indices.forEach { list.add(Kakko(it, s[it] == '(')) }
    var ans = -1
    while (list.isNotEmpty()) {
        val idx = list.indexOfLast { it.isLeft }
        val right = list[idx + 1]
        val left = list[idx]
        if(right.index == k - 1) {
            ans = left.index
            break
        } else if(left.index == k - 1) {
            ans = right.index
            break
        }
        list.removeAt(idx + 1)
        list.removeAt(idx)
    }
    println(ans + 1)
}

class Kakko(val index:Int, val isLeft:Boolean)
0