結果

問題 No.22 括弧の対応
ユーザー letrangerjpletrangerjp
提出日時 2017-06-03 09:54:50
言語 Ruby
(3.3.0)
結果
AC  
実行時間 82 ms / 5,000 ms
コード長 326 bytes
コンパイル時間 273 ms
コンパイル使用メモリ 11,360 KB
実行使用メモリ 15,300 KB
最終ジャッジ日時 2023-09-27 13:15:56
合計ジャッジ時間 2,830 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 82 ms
15,112 KB
testcase_01 AC 81 ms
15,124 KB
testcase_02 AC 82 ms
15,116 KB
testcase_03 AC 81 ms
15,032 KB
testcase_04 AC 81 ms
15,132 KB
testcase_05 AC 82 ms
15,132 KB
testcase_06 AC 82 ms
15,216 KB
testcase_07 AC 81 ms
15,032 KB
testcase_08 AC 82 ms
15,260 KB
testcase_09 AC 82 ms
15,036 KB
testcase_10 AC 81 ms
15,032 KB
testcase_11 AC 81 ms
15,120 KB
testcase_12 AC 81 ms
15,164 KB
testcase_13 AC 82 ms
15,300 KB
testcase_14 AC 80 ms
15,116 KB
testcase_15 AC 82 ms
15,288 KB
testcase_16 AC 82 ms
15,296 KB
testcase_17 AC 81 ms
15,132 KB
testcase_18 AC 81 ms
15,256 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

def f(s, n)
  # p [s,n]
  return s.size - f(s.reverse.tr("()",")("), s.size - n - 1) - 1if s[n] == ?)

  i = n
  g = lambda{|depth|
    return i if depth < 0
    i += 1
    if s[i] == ?(
      g.(depth+1)
    else
      g.(depth-1)
    end
  }
  g.(0)
end

N, K = gets.split.take(2).map(&:to_i)
S = gets[0,N]

p f(S, K-1) + 1
0