Submission #13147757


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 784 ms
Memory 15504 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 410 ms 14296 KB
random_02 702 ms 14308 KB
random_03 491 ms 14364 KB
random_04 784 ms 14156 KB
random_05 767 ms 14084 KB
random_06 573 ms 14176 KB
random_07 184 ms 14184 KB
random_08 136 ms 14508 KB
random_09 130 ms 15504 KB
random_10 578 ms 14216 KB
random_11 56 ms 14324 KB
random_12 54 ms 14076 KB
random_13 55 ms 14272 KB
random_21 53 ms 14080 KB
random_22 56 ms 14084 KB
random_23 54 ms 14076 KB
random_31 57 ms 13996 KB
random_32 54 ms 14260 KB
random_33 57 ms 14272 KB
random_41 54 ms 14260 KB
random_42 55 ms 14176 KB
random_43 53 ms 14192 KB
random_51 56 ms 14160 KB
random_52 53 ms 14048 KB
random_53 56 ms 14064 KB
random_61 329 ms 14168 KB
random_62 411 ms 14140 KB
random_63 530 ms 14284 KB
sample_01 52 ms 14168 KB
sample_02 51 ms 14304 KB
sample_03 53 ms 14328 KB
sample_04 51 ms 14164 KB