結果

問題 No.22 括弧の対応
ユーザー IJKTanabeIJKTanabe
提出日時 2017-10-20 00:57:05
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 318 ms / 5,000 ms
コード長 586 bytes
コンパイル時間 12,963 ms
コンパイル使用メモリ 424,788 KB
実行使用メモリ 53,856 KB
最終ジャッジ日時 2023-09-27 13:22:20
合計ジャッジ時間 19,581 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 293 ms
53,424 KB
testcase_01 AC 294 ms
53,592 KB
testcase_02 AC 294 ms
53,436 KB
testcase_03 AC 318 ms
53,476 KB
testcase_04 AC 308 ms
53,748 KB
testcase_05 AC 307 ms
53,668 KB
testcase_06 AC 309 ms
53,808 KB
testcase_07 AC 298 ms
53,616 KB
testcase_08 AC 307 ms
53,856 KB
testcase_09 AC 318 ms
53,800 KB
testcase_10 AC 314 ms
53,564 KB
testcase_11 AC 310 ms
53,500 KB
testcase_12 AC 305 ms
53,480 KB
testcase_13 AC 305 ms
53,556 KB
testcase_14 AC 295 ms
53,528 KB
testcase_15 AC 308 ms
53,844 KB
testcase_16 AC 317 ms
53,680 KB
testcase_17 AC 297 ms
53,564 KB
testcase_18 AC 304 ms
53,420 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:2:10: warning: parameter 'args' is never used
fun main(args: Array<String>) {
         ^
Main.kt:6:9: warning: variable 'l' is never used
    val l = Integer.parseInt(sc.next())
        ^

ソースコード

diff #

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

}
0