結果

問題 No.592 括弧の対応 (2)
ユーザー gemmarogemmaro
提出日時 2020-07-12 09:33:32
言語 Ruby
(3.3.0)
結果
AC  
実行時間 358 ms / 5,000 ms
コード長 311 bytes
コンパイル時間 124 ms
コンパイル使用メモリ 7,680 KB
実行使用メモリ 30,464 KB
最終ジャッジ日時 2024-04-22 10:06:03
合計ジャッジ時間 2,177 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 92 ms
12,160 KB
testcase_01 AC 358 ms
30,464 KB
testcase_02 AC 357 ms
30,464 KB
testcase_03 AC 357 ms
30,336 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

# frozen_string_literal: true

def solve
  result = Array.new(N)
  stack = []
  S.each_with_index do |s, i|
    case s
    when '('
      stack << i
    when ')'
      a = stack.pop
      result[i] = a
      result[a] = i
    end
  end
  result.map { _1 + 1 }
end

N = gets.to_i
S = gets.chomp.chars

puts solve
0