結果

問題 No.22 括弧の対応
ユーザー noriocnorioc
提出日時 2015-11-13 08:31:57
言語 Scala(Beta)
(3.4.0)
結果
AC  
実行時間 1,094 ms / 5,000 ms
コード長 714 bytes
コンパイル時間 15,470 ms
コンパイル使用メモリ 267,388 KB
実行使用メモリ 63,804 KB
最終ジャッジ日時 2023-08-20 05:29:18
合計ジャッジ時間 34,303 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,035 ms
63,312 KB
testcase_01 AC 981 ms
63,028 KB
testcase_02 AC 972 ms
63,216 KB
testcase_03 AC 1,003 ms
63,224 KB
testcase_04 AC 987 ms
63,052 KB
testcase_05 AC 1,009 ms
63,036 KB
testcase_06 AC 1,079 ms
63,024 KB
testcase_07 AC 1,076 ms
63,116 KB
testcase_08 AC 1,079 ms
63,804 KB
testcase_09 AC 1,042 ms
63,124 KB
testcase_10 AC 1,002 ms
63,024 KB
testcase_11 AC 1,058 ms
63,560 KB
testcase_12 AC 1,042 ms
62,948 KB
testcase_13 AC 1,030 ms
63,000 KB
testcase_14 AC 1,068 ms
63,100 KB
testcase_15 AC 1,094 ms
63,028 KB
testcase_16 AC 1,074 ms
63,172 KB
testcase_17 AC 1,055 ms
63,072 KB
testcase_18 AC 1,053 ms
62,988 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import math._
import util.control.Breaks._
import scala.collection.mutable.ArrayBuffer

object Main {
  def main(args: Array[String]) = {
    val sc = new java.util.Scanner(System.in)
    val n, k = sc.nextInt
    val s = sc.next

    val xs = new ArrayBuffer[(Int, Char)] // (インデックス, 括弧文字)
    breakable {
      for (i <- 0 to s.length-1) s(i) match {
        case '(' => xs.append((i, '('))
        case ')' => {
          assert(xs.last._2 == '(')
          if (i == k-1) {
            println(xs.last._1 + 1)
            break
          }
          if (xs.last._1 == k-1) {
            println(i+1)
            break
          }
        }
        xs.remove(xs.length-1)
      }
    }
  }
}
0