結果
問題 | No.684 Prefix Parenthesis |
ユーザー |
|
提出日時 | 2018-05-11 23:56:44 |
言語 | Ruby (3.4.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 474 bytes |
コンパイル時間 | 156 ms |
コンパイル使用メモリ | 7,296 KB |
実行使用メモリ | 24,960 KB |
最終ジャッジ日時 | 2024-06-28 09:07:12 |
合計ジャッジ時間 | 12,015 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 22 WA * 9 |
コンパイルメッセージ
Syntax OK
ソースコード
N = gets.to_iS = gets.chompopen = close = set = 0a = []S.chars{|c|if c == ?(open += 1elseif open > 0open -= 1set += 1elseclose += 1endenda << [set, open, close]}a.sort_by!{|set, open, close|[-(open - close), -set]}open_cnt = close_cnt = cnt = 0a.each_with_index{|(set, open, close), i|close_cnt += close if i != 0open_cnt += open if i != a.size - 1cnt += set}p (cnt + [close_cnt, open_cnt].min)*2