Submission #51483115


Source Code Expand

(N,K),*B = $<.map{|ln| ln.split.map(&:to_i) }
KVCVC = [[0,0]]
while (c,v = B.pop)
	v3 = c3 = nil
	KVCVC.each{|vcvc|
		v1,c1,v2,c2 = vcvc
		if v3
			if v2 # 1,2,3
				if v1<v3
					vcvc[0] = v3
					vcvc[1] = c3
					if c1!=c3
						vcvc[2] = v1
						vcvc[3] = c1
					end
				elsif v2<v3
					if c1!=c3
						vcvc[2] = v3
						vcvc[3] = c3
					end
				end
			elsif v1 # 1,3
				if v1<v3
					vcvc[0] = v3
					vcvc[1] = c3
					if c1!=c3
						vcvc[2] = v1
						vcvc[3] = c1
					end
				else
					vcvc<<v3<<c3 if c1!=c3
				end
			else # 3
				vcvc<<v3<<c3
			end
			v3 = c3 = nil
		end
		if v1
			if c1!=c
				v3 = v+v1
				c3 = c
			elsif v2
				v3 = v+v2
				c3 = c
			end
		end
	}<<(v3 ? [v3,c3] : [])
	KVCVC.shift if KVCVC[K+1]
end
p(KVCVC[0][0]||-1)

Submission Info

Submission Time
Task E - Colorful Subsequence
User ds14050
Language Ruby (ruby 3.2.2)
Score 0
Code Size 811 Byte
Status TLE
Exec Time 5522 ms
Memory 49208 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 525
Status
AC × 3
AC × 18
TLE × 20
Set Name Test Cases
Sample example_00.txt, example_01.txt, example_02.txt
All example_00.txt, example_01.txt, example_02.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt
Case Name Status Exec Time Memory
example_00.txt AC 42 ms 17136 KiB
example_01.txt AC 42 ms 17184 KiB
example_02.txt AC 42 ms 17236 KiB
hand_00.txt TLE 5519 ms 36680 KiB
hand_01.txt TLE 5520 ms 45688 KiB
hand_02.txt AC 297 ms 46196 KiB
hand_03.txt AC 4947 ms 32940 KiB
hand_04.txt AC 42 ms 16860 KiB
hand_05.txt AC 42 ms 17308 KiB
hand_06.txt AC 54 ms 17536 KiB
hand_07.txt AC 43 ms 17272 KiB
random_00.txt AC 615 ms 41304 KiB
random_01.txt TLE 5519 ms 41888 KiB
random_02.txt AC 4935 ms 42496 KiB
random_03.txt TLE 5519 ms 41496 KiB
random_04.txt AC 735 ms 41548 KiB
random_05.txt TLE 5519 ms 42792 KiB
random_06.txt AC 4588 ms 42988 KiB
random_07.txt TLE 5516 ms 39636 KiB
random_08.txt TLE 5520 ms 49208 KiB
random_09.txt TLE 5522 ms 41364 KiB
random_10.txt TLE 5517 ms 48032 KiB
random_11.txt TLE 5519 ms 39172 KiB
random_12.txt TLE 5520 ms 49040 KiB
random_13.txt TLE 5519 ms 38188 KiB
random_14.txt AC 3820 ms 43328 KiB
random_15.txt TLE 5519 ms 38668 KiB
random_16.txt AC 2878 ms 42076 KiB
random_17.txt TLE 5519 ms 38204 KiB
random_18.txt TLE 5519 ms 39700 KiB
random_19.txt TLE 5519 ms 37836 KiB
random_20.txt TLE 5520 ms 45804 KiB
random_21.txt TLE 5514 ms 39828 KiB
random_22.txt AC 2597 ms 42948 KiB
random_23.txt TLE 5519 ms 38212 KiB
random_24.txt AC 4435 ms 43068 KiB
random_25.txt TLE 5519 ms 37976 KiB
random_26.txt AC 4599 ms 46344 KiB