Submission #13160001


Source Code Expand

Copy
F = lambda{|s|
	z = s.size
	r = l = i = 0
	r = i = s.index(?(,0)||z if s[0] == ?)
	until i == z
		j = s.index(?),i)||z # i(((j
		k = s.index(?(,j)||z # j)))k

		rr = k-j-j+i-l
		if 0<rr
			r += rr
			l = 0
		else
			l = -rr
		end

		i = k
	end
	return r,l # ),(
}
N = gets.to_i

n = ll = r = l = rr = 0
r_min = []
l_min = []
until N < n+=1
	r_,l_ = F[gets.chomp]

	if r_ == 0
		ll += l_
	elsif l_ == 0
		rr += r_
	else
		r += r_
		l += l_
		r_min = r_min.push([r_,n]).min_by(2){|_,|_}
		l_min = l_min.push([l_,n]).min_by(2){|_,|_}
	end
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 721 Byte
Status
Exec Time 821 ms
Memory 14380 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 410 ms 14160 KB
random_02 773 ms 14160 KB
random_03 508 ms 14244 KB
random_04 821 ms 14116 KB
random_05 800 ms 14236 KB
random_06 422 ms 14248 KB
random_07 159 ms 14128 KB
random_08 122 ms 14260 KB
random_09 118 ms 14032 KB
random_10 424 ms 14244 KB
random_11 54 ms 14148 KB
random_12 50 ms 14236 KB
random_13 53 ms 14224 KB
random_21 52 ms 14300 KB
random_22 53 ms 14380 KB
random_23 51 ms 14100 KB
random_31 53 ms 14312 KB
random_32 51 ms 14276 KB
random_33 53 ms 14176 KB
random_41 51 ms 14260 KB
random_42 54 ms 14124 KB
random_43 51 ms 14248 KB
random_51 54 ms 14148 KB
random_52 52 ms 14128 KB
random_53 53 ms 14196 KB
random_61 390 ms 14316 KB
random_62 507 ms 14252 KB
random_63 701 ms 14256 KB
sample_01 53 ms 14192 KB
sample_02 52 ms 14080 KB
sample_03 52 ms 14172 KB
sample_04 51 ms 14208 KB