結果

問題 No.684 Prefix Parenthesis
ユーザー 👑 hos.lyrichos.lyric
提出日時 2019-01-29 09:39:31
言語 Ruby
(3.3.0)
結果
AC  
実行時間 591 ms / 2,000 ms
コード長 163 bytes
コンパイル時間 293 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 25,088 KB
最終ジャッジ日時 2024-04-17 09:23:25
合計ジャッジ時間 11,353 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
12,160 KB
testcase_01 AC 82 ms
12,288 KB
testcase_02 AC 83 ms
12,288 KB
testcase_03 AC 212 ms
15,232 KB
testcase_04 AC 374 ms
20,096 KB
testcase_05 AC 439 ms
20,992 KB
testcase_06 AC 200 ms
15,360 KB
testcase_07 AC 396 ms
20,736 KB
testcase_08 AC 114 ms
12,800 KB
testcase_09 AC 116 ms
13,184 KB
testcase_10 AC 548 ms
24,448 KB
testcase_11 AC 346 ms
20,736 KB
testcase_12 AC 125 ms
13,312 KB
testcase_13 AC 465 ms
24,192 KB
testcase_14 AC 453 ms
23,936 KB
testcase_15 AC 207 ms
16,128 KB
testcase_16 AC 432 ms
23,808 KB
testcase_17 AC 251 ms
18,304 KB
testcase_18 AC 89 ms
12,160 KB
testcase_19 AC 488 ms
24,960 KB
testcase_20 AC 511 ms
24,832 KB
testcase_21 AC 556 ms
24,960 KB
testcase_22 AC 440 ms
24,064 KB
testcase_23 AC 438 ms
24,064 KB
testcase_24 AC 541 ms
24,576 KB
testcase_25 AC 591 ms
24,576 KB
testcase_26 AC 84 ms
12,288 KB
testcase_27 AC 85 ms
12,160 KB
testcase_28 AC 85 ms
12,160 KB
testcase_29 AC 477 ms
25,088 KB
testcase_30 AC 490 ms
24,960 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

a=b=0
l=[]
n=gets.to_i
gets.chomp.chars{|x|a-=x<')'?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]}.map{|c,d|b<a+d&&b=a+d;a+=c}
p n*(n+1)/2+a-2*b
0