結果

問題 No.22 括弧の対応
ユーザー 💕💖💞💕💖💞
提出日時 2017-04-08 19:50:28
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 316 ms / 5,000 ms
コード長 602 bytes
コンパイル時間 14,679 ms
コンパイル使用メモリ 418,416 KB
実行使用メモリ 53,204 KB
最終ジャッジ日時 2023-09-27 13:14:47
合計ジャッジ時間 21,176 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 294 ms
52,804 KB
testcase_01 AC 292 ms
52,640 KB
testcase_02 AC 294 ms
52,688 KB
testcase_03 AC 316 ms
52,784 KB
testcase_04 AC 306 ms
52,800 KB
testcase_05 AC 305 ms
52,748 KB
testcase_06 AC 314 ms
53,196 KB
testcase_07 AC 313 ms
52,796 KB
testcase_08 AC 306 ms
52,740 KB
testcase_09 AC 299 ms
53,016 KB
testcase_10 AC 309 ms
52,900 KB
testcase_11 AC 294 ms
52,984 KB
testcase_12 AC 306 ms
52,860 KB
testcase_13 AC 307 ms
52,876 KB
testcase_14 AC 291 ms
52,664 KB
testcase_15 AC 316 ms
53,204 KB
testcase_16 AC 314 ms
53,040 KB
testcase_17 AC 291 ms
53,036 KB
testcase_18 AC 292 ms
52,660 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:1:10: warning: parameter 'args' is never used
fun main(args: Array<String>) {
         ^

ソースコード

diff #

fun main(args: Array<String>) {
  val (N, K) = readLine()!!.split(" ").map{ x -> x.toInt() }
  val se     = readLine()!!
  val start  = se[K-1]
  if(start == '(') {
    var c = 0
    for(i in (K..N) ) {
      if(se[i] == '(') c++
      else{
        if(c==0) {
          println(i+1)
          break
        }else{
          c--
        }
      }
    }
  } else if( start == ')') {
    var c = 0
    for(i in (K-2 downTo 0) ) {
      if(se[i] == ')') {
        c++
      }
      else{
        if(c==0) {
          println(i+1)
          break
        }else{
          c--
        }
      }
    }
  }
}
0