結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 88 ms
12,160 KB
testcase_01 AC 87 ms
12,160 KB
testcase_02 AC 88 ms
12,288 KB
testcase_03 AC 221 ms
15,488 KB
testcase_04 AC 410 ms
20,352 KB
testcase_05 AC 473 ms
20,736 KB
testcase_06 AC 219 ms
15,232 KB
testcase_07 AC 423 ms
20,608 KB
testcase_08 AC 128 ms
12,928 KB
testcase_09 AC 134 ms
13,184 KB
testcase_10 AC 606 ms
24,448 KB
testcase_11 AC 373 ms
20,480 KB
testcase_12 AC 139 ms
13,440 KB
testcase_13 AC 498 ms
24,064 KB
testcase_14 AC 482 ms
23,680 KB
testcase_15 AC 222 ms
16,000 KB
testcase_16 AC 461 ms
23,808 KB
testcase_17 AC 274 ms
17,792 KB
testcase_18 AC 94 ms
12,160 KB
testcase_19 AC 525 ms
24,832 KB
testcase_20 AC 554 ms
24,832 KB
testcase_21 AC 598 ms
24,960 KB
testcase_22 AC 467 ms
23,936 KB
testcase_23 AC 466 ms
24,064 KB
testcase_24 AC 583 ms
24,448 KB
testcase_25 AC 632 ms
24,576 KB
testcase_26 AC 87 ms
12,160 KB
testcase_27 AC 89 ms
12,416 KB
testcase_28 AC 88 ms
12,160 KB
testcase_29 AC 513 ms
24,960 KB
testcase_30 AC 533 ms
24,960 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:d-c]
}.each{|c,d|
  b>a+d&&b=a+d
  a+=c
}
p n*(n+1)/2-a+2*b
0