結果
問題 | No.22 括弧の対応 |
ユーザー |
|
提出日時 | 2017-10-31 19:37:22 |
言語 | Ruby (3.4.1) |
結果 |
AC
|
実行時間 | 85 ms / 5,000 ms |
コード長 | 307 bytes |
コンパイル時間 | 47 ms |
コンパイル使用メモリ | 7,296 KB |
実行使用メモリ | 12,416 KB |
最終ジャッジ日時 | 2024-07-20 07:26:29 |
合計ジャッジ時間 | 2,579 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 19 |
コンパイルメッセージ
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 == ")" if ans[0] == k puts ans[1] exit 0 end if ans[1] == k puts ans[0] exit 0 end end