結果

問題 No.457 (^^*)
ユーザー cielciel
提出日時 2016-12-08 21:24:47
言語 Ruby
(3.3.0)
結果
TLE  
実行時間 -
コード長 493 bytes
コンパイル時間 93 ms
コンパイル使用メモリ 11,500 KB
実行使用メモリ 20,108 KB
最終ジャッジ日時 2023-08-19 02:34:22
合計ジャッジ時間 6,647 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 67 ms
15,368 KB
testcase_01 AC 67 ms
15,312 KB
testcase_02 AC 68 ms
15,308 KB
testcase_03 AC 68 ms
15,108 KB
testcase_04 AC 68 ms
15,160 KB
testcase_05 AC 72 ms
15,180 KB
testcase_06 AC 69 ms
15,248 KB
testcase_07 AC 80 ms
15,348 KB
testcase_08 AC 133 ms
15,148 KB
testcase_09 AC 309 ms
15,368 KB
testcase_10 AC 1,745 ms
15,444 KB
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

#!/usr/bin/ruby
def solve(s)
	al=[]
	ar=[]
	ah=[0]*s.size
	ast=[]
	s.size.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|ar.each{|r|next if l>=r
		hidx=(l...r).bsearch{|i|ah[i]>=ah[l]+2}
		next if !hidx
		st=ast.bsearch{|e|e>=hidx}||s.size
		if st<r
			#p [l,st,r]
			ret+=1
		end
	}}
	ret
end
s=gets.chomp
puts [solve(s),solve(s.reverse.tr('()',')('))]*' '
0