結果

問題 No.22 括弧の対応
ユーザー Takuya NoguchiTakuya Noguchi
提出日時 2018-03-21 17:56:03
言語 Ruby
(3.3.0)
結果
AC  
実行時間 78 ms / 5,000 ms
コード長 297 bytes
コンパイル時間 228 ms
コンパイル使用メモリ 11,428 KB
実行使用メモリ 16,360 KB
最終ジャッジ日時 2023-09-27 13:25:46
合計ジャッジ時間 2,474 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
15,208 KB
testcase_01 AC 73 ms
15,020 KB
testcase_02 AC 67 ms
15,076 KB
testcase_03 AC 74 ms
16,360 KB
testcase_04 AC 70 ms
15,388 KB
testcase_05 AC 74 ms
15,440 KB
testcase_06 AC 77 ms
15,624 KB
testcase_07 AC 74 ms
15,624 KB
testcase_08 AC 73 ms
15,600 KB
testcase_09 AC 72 ms
15,600 KB
testcase_10 AC 78 ms
15,680 KB
testcase_11 AC 74 ms
15,412 KB
testcase_12 AC 76 ms
15,424 KB
testcase_13 AC 77 ms
15,616 KB
testcase_14 AC 72 ms
15,124 KB
testcase_15 AC 72 ms
16,296 KB
testcase_16 AC 74 ms
16,208 KB
testcase_17 AC 68 ms
15,092 KB
testcase_18 AC 75 ms
15,036 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

_, K = gets.split.map(&:to_i)
S = gets.chomp

paren_stack = []
paren_table = {}
S.chars.each.with_index(1) do |paren, i|
  if paren == '('
    paren_stack << i
  else
    paren_index = paren_stack.pop
    paren_table[paren_index] = i
    paren_table[i] = paren_index
  end
end

puts paren_table[K]
0