結果

問題 No.22 括弧の対応
ユーザー IJKTanabeIJKTanabe
提出日時 2017-10-19 23:05:35
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 299 ms / 5,000 ms
コード長 489 bytes
コンパイル時間 12,076 ms
コンパイル使用メモリ 410,140 KB
実行使用メモリ 54,116 KB
最終ジャッジ日時 2023-09-27 13:21:36
合計ジャッジ時間 17,060 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 282 ms
53,576 KB
testcase_01 AC 279 ms
53,544 KB
testcase_02 AC 281 ms
53,692 KB
testcase_03 AC 297 ms
54,116 KB
testcase_04 AC 295 ms
53,612 KB
testcase_05 AC 289 ms
53,416 KB
testcase_06 AC 295 ms
53,556 KB
testcase_07 AC 297 ms
53,412 KB
testcase_08 AC 289 ms
53,340 KB
testcase_09 AC 296 ms
53,748 KB
testcase_10 AC 297 ms
53,484 KB
testcase_11 AC 289 ms
53,820 KB
testcase_12 AC 299 ms
53,492 KB
testcase_13 AC 295 ms
53,452 KB
testcase_14 AC 282 ms
53,512 KB
testcase_15 AC 294 ms
53,616 KB
testcase_16 AC 298 ms
53,616 KB
testcase_17 AC 284 ms
53,444 KB
testcase_18 AC 291 ms
53,320 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:2:10: warning: parameter 'args' is never used
fun main(args: Array<String>) {
         ^
Main.kt:4:9: warning: variable 'l' is never used
    val l = Integer.parseInt(cin.next())
        ^

ソースコード

diff #

import java.util.*
fun main(args: Array<String>) {
    val cin = Scanner(System.`in`)
    val l = Integer.parseInt(cin.next())
    var index = Integer.parseInt(cin.next()) -1
    val b = cin.next() //括弧の文字列
    
    val start = b.get(index) //開始位置の文字
    val dir = if(start.equals('(')) 1 else -1
    
    var count = 0
    do {
        index += dir
        count += if(b.get(index).equals(start)) 1 else -1
    } while(count > -1)
    
    println (index + 1)
}
0