結果
| 問題 | 
                            No.22 括弧の対応
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2017-10-31 19:35:59 | 
| 言語 | Ruby  (3.4.1)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 244 bytes | 
| コンパイル時間 | 46 ms | 
| コンパイル使用メモリ | 7,552 KB | 
| 実行使用メモリ | 12,416 KB | 
| 最終ジャッジ日時 | 2024-11-22 11:12:36 | 
| 合計ジャッジ時間 | 2,781 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 4 WA * 15 | 
コンパイルメッセージ
Main.rb:1: warning: assigned but unused variable - n Syntax OK
ソースコード
n, k = gets.split.map(&:to_i)
s = gets
stack = []
ans = []
s.each_char.with_index do |c, idx|
    stack.push(idx) if c == "("
    ans = [stack.pop + 1, idx + 1] if c == ")"
    
    puts ans[1] if ans[0] == k
    puts ans[0] if ans[1] == k
end