結果
| 問題 |
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_i
S = gets.chomp
open = close = set = 0
a = []
S.chars{|c|
if c == ?(
open += 1
else
if open > 0
open -= 1
set += 1
else
close += 1
end
end
a << [set, open, close]
}
a.sort_by!{|set, open, close|
[-(open - close), -set]
}
open_cnt = close_cnt = cnt = 0
a.each_with_index{|(set, open, close), i|
close_cnt += close if i != 0
open_cnt += open if i != a.size - 1
cnt += set
}
p (cnt + [close_cnt, open_cnt].min)*2