結果

問題 No.684 Prefix Parenthesis
ユーザー letrangerjpletrangerjp
提出日時 2018-05-11 23:56:44
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 474 bytes
コンパイル時間 535 ms
コンパイル使用メモリ 11,320 KB
実行使用メモリ 27,536 KB
最終ジャッジ日時 2023-09-10 17:56:42
合計ジャッジ時間 12,504 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
15,332 KB
testcase_01 AC 85 ms
15,072 KB
testcase_02 AC 83 ms
15,096 KB
testcase_03 AC 204 ms
18,100 KB
testcase_04 AC 390 ms
22,832 KB
testcase_05 AC 422 ms
23,724 KB
testcase_06 AC 199 ms
17,976 KB
testcase_07 WA -
testcase_08 AC 120 ms
15,844 KB
testcase_09 WA -
testcase_10 AC 552 ms
26,588 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 417 ms
26,632 KB
testcase_14 AC 404 ms
26,184 KB
testcase_15 AC 195 ms
19,080 KB
testcase_16 AC 401 ms
26,308 KB
testcase_17 AC 263 ms
21,360 KB
testcase_18 AC 88 ms
15,092 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 577 ms
27,224 KB
testcase_22 AC 423 ms
27,536 KB
testcase_23 AC 410 ms
26,740 KB
testcase_24 AC 563 ms
27,396 KB
testcase_25 WA -
testcase_26 AC 83 ms
15,160 KB
testcase_27 AC 85 ms
15,088 KB
testcase_28 AC 83 ms
15,332 KB
testcase_29 WA -
testcase_30 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

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
0