結果

問題 No.684 Prefix Parenthesis
ユーザー 👑 hos.lyrichos.lyric
提出日時 2019-01-28 11:51:28
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 184 bytes
コンパイル時間 39 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 24,960 KB
最終ジャッジ日時 2024-04-14 22:32:52
合計ジャッジ時間 12,587 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 99 ms
12,288 KB
testcase_01 AC 91 ms
12,288 KB
testcase_02 AC 91 ms
12,288 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 435 ms
20,608 KB
testcase_08 WA -
testcase_09 AC 134 ms
13,184 KB
testcase_10 WA -
testcase_11 AC 377 ms
20,608 KB
testcase_12 AC 140 ms
13,312 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 465 ms
23,808 KB
testcase_17 AC 275 ms
17,792 KB
testcase_18 AC 95 ms
12,416 KB
testcase_19 AC 525 ms
24,832 KB
testcase_20 AC 571 ms
24,832 KB
testcase_21 WA -
testcase_22 AC 469 ms
24,192 KB
testcase_23 AC 471 ms
24,064 KB
testcase_24 AC 581 ms
24,576 KB
testcase_25 AC 634 ms
24,704 KB
testcase_26 AC 91 ms
12,160 KB
testcase_27 AC 90 ms
12,160 KB
testcase_28 AC 91 ms
12,160 KB
testcase_29 AC 526 ms
24,832 KB
testcase_30 AC 547 ms
24,832 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

a=b=0
l=[]
n=gets.to_i
gets.chomp.chars{|c|
  a+=c<')'?1:-1
  b>a&&b=a
  l<<[a,b]
}
a=b=0
l.sort_by{|c,d|
  [e=-c<=>0,e<0?-d:c-d]
}.each{|c,d|
  b>a+d&&b=a+d
  a+=c
}
p n*(n+1)/2-a+2*b
0