結果

問題 No.457 (^^*)
ユーザー cielciel
提出日時 2016-12-08 22:28:42
言語 Ruby
(3.3.0)
結果
AC  
実行時間 106 ms / 2,000 ms
コード長 492 bytes
コンパイル時間 127 ms
コンパイル使用メモリ 11,548 KB
実行使用メモリ 15,788 KB
最終ジャッジ日時 2023-08-27 02:41:13
合計ジャッジ時間 3,496 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
15,256 KB
testcase_01 AC 77 ms
15,128 KB
testcase_02 AC 77 ms
15,032 KB
testcase_03 AC 76 ms
15,096 KB
testcase_04 AC 77 ms
15,328 KB
testcase_05 AC 75 ms
15,188 KB
testcase_06 AC 81 ms
15,196 KB
testcase_07 AC 79 ms
15,208 KB
testcase_08 AC 78 ms
15,192 KB
testcase_09 AC 83 ms
15,264 KB
testcase_10 AC 91 ms
15,348 KB
testcase_11 AC 106 ms
15,752 KB
testcase_12 AC 102 ms
15,648 KB
testcase_13 AC 104 ms
15,788 KB
testcase_14 AC 86 ms
15,784 KB
testcase_15 AC 102 ms
15,624 KB
testcase_16 AC 90 ms
15,652 KB
testcase_17 AC 101 ms
15,632 KB
testcase_18 AC 77 ms
15,244 KB
testcase_19 AC 76 ms
15,132 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

#!/usr/bin/ruby
def solve(s)
	len=s.size
	al=[]
	ar=[]
	ah=[0]*len
	ast=[]
	len.times{|i|
		if s[i]==?(
			al<<i
		elsif s[i]==?)
			ar<<i
		elsif s[i]==?^
			ah[i]+=1
		elsif s[i]==?*
			ast<<i
		end
	}
	(1...s.size).each{|i|ah[i]+=ah[i-1]}
	ret=0
	al.each{|l|
		hidx=(l...len).bsearch{|i|ah[i]>=ah[l]+2}||len
		st=ast.bsearch{|e|e>=hidx}
		break if !st
		ret+=ar.size-((0...ar.size).bsearch{|i|ar[i]>=st}||ar.size)
	}
	ret
end
s=gets.chomp
puts [solve(s),solve(s.reverse.tr('()',')('))]*' '
0