Submission #57906057


Source Code Expand

N, = C = $<.read.split.map(&:to_i)
C[0] = 0
I = (N+1).times.sort_by{|i| C[i] }
S = I.inject([0]){|s,i| s<<s[-1]+C[i] }
K = (0..C.sum/5+1).bsearch{|k|
	under2k = I.bsearch_index{|i| k+k<=C[i] }||I.size # 個数
	under2k = S[under2k]+(k+k)*(N+1-under2k) # 数
	over2k = S[-1]-under2k
	next under2k+[over2k,k].min<5*k
}-1
TA = []
3.times{
	I.reverse_each{|i|
		k = [C[i],K,5*K-TA.size].min
		C[i] -= k
		TA.concat [i]*k
	}
}
warn K
warn TA.size==5*K
A = K==0 ? [] : TA.each_slice(K).to_a.transpose
A.map!{|a5|
	a5.delete a = a5.pop
	a5<<a
	a5.unshift a if a5.size<5
	a5.insert 2,a if a5.size<5
	next a5
}
warn A.all?{|a5| a5.size==5 && a5.each_cons(2).all?{ _1!=_2 } }
puts K,A.map{|a5| a5*' ' }

Submission Info

Submission Time
Task G - Quintuple Scoop Ice Cream
User ds14050
Language Ruby (ruby 3.2.2)
Score 500
Code Size 723 Byte
Status AC
Exec Time 351 ms
Memory 47564 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 4
AC × 52
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 02_edge_27.txt, 02_edge_28.txt, 02_edge_29.txt, 02_edge_30.txt, 02_edge_31.txt, 02_edge_32.txt, 02_edge_33.txt, 02_edge_34.txt, 02_edge_35.txt, 02_edge_36.txt, 02_edge_37.txt, 02_edge_38.txt, 02_edge_39.txt, 02_edge_40.txt, 02_edge_41.txt, 02_edge_42.txt, 03_handmade_43.txt, 03_handmade_44.txt, 03_handmade_45.txt, 03_handmade_46.txt, 03_handmade_47.txt, 03_handmade_48.txt, 03_handmade_49.txt, 03_handmade_50.txt, 03_handmade_51.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 90 ms 17204 KiB
00_sample_01.txt AC 49 ms 17116 KiB
00_sample_02.txt AC 49 ms 17300 KiB
00_sample_03.txt AC 49 ms 17316 KiB
01_random_04.txt AC 351 ms 47564 KiB
01_random_05.txt AC 347 ms 46924 KiB
01_random_06.txt AC 349 ms 46924 KiB
01_random_07.txt AC 148 ms 26072 KiB
01_random_08.txt AC 187 ms 33412 KiB
01_random_09.txt AC 245 ms 41100 KiB
01_random_10.txt AC 328 ms 45284 KiB
01_random_11.txt AC 217 ms 32996 KiB
01_random_12.txt AC 175 ms 29668 KiB
01_random_13.txt AC 175 ms 27692 KiB
01_random_14.txt AC 175 ms 27764 KiB
01_random_15.txt AC 124 ms 24608 KiB
01_random_16.txt AC 148 ms 26332 KiB
01_random_17.txt AC 170 ms 28632 KiB
01_random_18.txt AC 122 ms 24076 KiB
01_random_19.txt AC 113 ms 23564 KiB
01_random_20.txt AC 167 ms 33148 KiB
01_random_21.txt AC 197 ms 30784 KiB
01_random_22.txt AC 277 ms 39416 KiB
01_random_23.txt AC 109 ms 22064 KiB
01_random_24.txt AC 211 ms 37548 KiB
01_random_25.txt AC 241 ms 39532 KiB
01_random_26.txt AC 176 ms 32336 KiB
02_edge_27.txt AC 198 ms 36744 KiB
02_edge_28.txt AC 220 ms 32556 KiB
02_edge_29.txt AC 229 ms 33516 KiB
02_edge_30.txt AC 234 ms 33388 KiB
02_edge_31.txt AC 250 ms 39620 KiB
02_edge_32.txt AC 252 ms 40408 KiB
02_edge_33.txt AC 298 ms 38516 KiB
02_edge_34.txt AC 204 ms 27576 KiB
02_edge_35.txt AC 138 ms 27660 KiB
02_edge_36.txt AC 270 ms 31816 KiB
02_edge_37.txt AC 181 ms 25716 KiB
02_edge_38.txt AC 265 ms 39020 KiB
02_edge_39.txt AC 184 ms 25584 KiB
02_edge_40.txt AC 232 ms 33528 KiB
02_edge_41.txt AC 199 ms 26376 KiB
02_edge_42.txt AC 260 ms 41628 KiB
03_handmade_43.txt AC 335 ms 47000 KiB
03_handmade_44.txt AC 49 ms 17224 KiB
03_handmade_45.txt AC 214 ms 25920 KiB
03_handmade_46.txt AC 176 ms 26464 KiB
03_handmade_47.txt AC 172 ms 26392 KiB
03_handmade_48.txt AC 194 ms 26576 KiB
03_handmade_49.txt AC 175 ms 26376 KiB
03_handmade_50.txt AC 48 ms 17160 KiB
03_handmade_51.txt AC 208 ms 40560 KiB