結果
| 問題 |
No.22 括弧の対応
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-12-22 20:24:14 |
| 言語 | Ruby (3.4.1) |
| 結果 |
AC
|
| 実行時間 | 99 ms / 5,000 ms |
| コード長 | 291 bytes |
| コンパイル時間 | 235 ms |
| コンパイル使用メモリ | 7,296 KB |
| 実行使用メモリ | 12,288 KB |
| 最終ジャッジ日時 | 2024-07-20 07:06:02 |
| 合計ジャッジ時間 | 2,581 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 19 |
コンパイルメッセージ
Main.rb:1: warning: assigned but unused variable - n Syntax OK
ソースコード
n, k = gets.split.map(&:to_i)
s = gets.chomp
stack = []
s.each_char.with_index do |c, i|
case c
when '('
stack << i
when ')'
if i == k - 1
puts stack[-1] + 1
break
elsif stack[-1] == k - 1
puts i + 1
break
else
stack.pop
end
end
end