Submission #13156522


Source Code Expand

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

ll = r = l = rr = 0
$<.each{|ln|
	s = ln.chomp.gsub(re,'')
	next if s.empty?

	if s[0] == ?(
		ll += s.size
	elsif s[-1] == ?)
		rr += s.size
	else
		i = s.index(?()
		# r), (l, i), (s.size-i
		r += i-l if l<i
		l = [l-i,0].max+s.size-i
	end
}

puts(ll<r||rr<l||ll+l!=rr+r ? 'No' : 'Yes')

Submission Info

Submission Time
Task F - Bracket Sequencing
User ds14050
Language Ruby (2.7.1)
Score 0
Code Size 340 Byte
Status
Exec Time 781 ms
Memory 16400 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 sample_01, sample_02, sample_03, sample_04
All 0 / 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 422 ms 14204 KB
random_02 704 ms 14032 KB
random_03 497 ms 14100 KB
random_04 781 ms 14376 KB
random_05 775 ms 14244 KB
random_06 573 ms 14076 KB
random_07 180 ms 14244 KB
random_08 163 ms 14724 KB
random_09 212 ms 16400 KB
random_10 585 ms 14268 KB
random_11 53 ms 14204 KB
random_12 56 ms 14100 KB
random_13 53 ms 14088 KB
random_21 55 ms 14208 KB
random_22 54 ms 14180 KB
random_23 55 ms 14288 KB
random_31 53 ms 14236 KB
random_32 57 ms 14296 KB
random_33 54 ms 14104 KB
random_41 57 ms 14308 KB
random_42 54 ms 14144 KB
random_43 55 ms 14232 KB
random_51 53 ms 14268 KB
random_52 55 ms 14016 KB
random_53 54 ms 14324 KB
random_61 351 ms 14176 KB
random_62 414 ms 14232 KB
random_63 539 ms 14112 KB
sample_01 50 ms 14340 KB
sample_02 54 ms 13992 KB
sample_03 51 ms 14168 KB
sample_04 52 ms 14180 KB