Submission #13158713


Source Code Expand

Copy
re = /(?<p>\(\g<p>*\))/

ll = r = l = rr = 0
r_min = []
l_min = []
gets.to_i.times{|n|
	s = gets.chomp.gsub(re,'')
	next if s.empty?

	if s[0] == ?(
		ll += s.size
	elsif s[-1] == ?)
		rr += s.size
	else
		i = s.index(?()
		r += i
		l += s.size-i
		r_min = r_min.push([i,n]).sort_by{|_,|_}.take(2)
		l_min = l_min.push([s.size-i,n]).sort_by{|_,|_}.take(2)
	end
}

if ll+l == rr+r and r_min.empty? || r_min.product(l_min).any?{|(r,ri),(l,li)| ri!=li && ll>=r && l<=rr }
	puts'Yes'
else
	puts'No'
end

Submission Info

Submission Time
Task F - Bracket Sequencing
User ds14050
Language Ruby (2.7.1)
Score 600
Code Size 526 Byte
Status
Exec Time 1014 ms
Memory 16076 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 sample_01, sample_02, sample_03, sample_04
All 600 / 600 random_01, random_02, random_03, random_04, random_05, random_06, random_07, random_08, random_09, random_10, random_11, random_12, random_13, random_21, random_22, random_23, random_31, random_32, random_33, random_41, random_42, random_43, random_51, random_52, random_53, random_61, random_62, random_63, sample_01, sample_02, sample_03, sample_04
Case Name Status Exec Time Memory
random_01 598 ms 14352 KB
random_02 900 ms 14168 KB
random_03 697 ms 14248 KB
random_04 875 ms 13992 KB
random_05 880 ms 14016 KB
random_06 624 ms 14152 KB
random_07 184 ms 14036 KB
random_08 162 ms 14492 KB
random_09 215 ms 16076 KB
random_10 629 ms 14088 KB
random_11 58 ms 14220 KB
random_12 55 ms 14056 KB
random_13 60 ms 14100 KB
random_21 54 ms 14404 KB
random_22 55 ms 13992 KB
random_23 55 ms 14164 KB
random_31 54 ms 14416 KB
random_32 59 ms 14168 KB
random_33 54 ms 14364 KB
random_41 55 ms 13992 KB
random_42 56 ms 14328 KB
random_43 54 ms 14320 KB
random_51 56 ms 14408 KB
random_52 54 ms 14180 KB
random_53 56 ms 14280 KB
random_61 593 ms 14060 KB
random_62 748 ms 14268 KB
random_63 1014 ms 14232 KB
sample_01 52 ms 14260 KB
sample_02 52 ms 14320 KB
sample_03 53 ms 14272 KB
sample_04 57 ms 14068 KB