Submission #20211491


Source Code Expand

Copy
P = $<.read.split.map(&:to_i)
C = Array.new(P.size+1){ [] }
P.each.with_index(1).reverse_each{|p,v|
even,odd = C[v].partition{ _3<1 }
ao = tk = 0
odd.sort_by!{ _2-_1 }
while 1 < odd.size
(o00,o01),(o10,o11) = odd.shift(2)
ao += o00+o11
tk += o01+o10
end
unless odd.empty?
o0,o1 = odd[0]
ao += o0
tk += o1
end
even.each(&[lambda{|(e0,e1)|
ao += e0
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
P = $<.read.split.map(&:to_i)

C = Array.new(P.size+1){ [] }
P.each.with_index(1).reverse_each{|p,v|
	even,odd = C[v].partition{ _3<1 }
	ao = tk = 0

	odd.sort_by!{ _2-_1 }
	while 1 < odd.size
		(o00,o01),(o10,o11) = odd.shift(2)
		ao += o00+o11
		tk += o01+o10
	end
	unless odd.empty?
		o0,o1 = odd[0]
		ao += o0
		tk += o1
	end

	even.each(&[lambda{|(e0,e1)|
		ao += e0
		tk += e1
	},lambda{|(e0,e1)|
		e0,e1 = e1,e0 if e0<e1
		ao += e0
		tk += e1
	}][odd.size&1])

	C[p] << [ao,tk+1,1-odd.size&1]
}

(_,e1),(_,o1) = C[-1]
p(o1||e1)

Submission Info

Submission Time
Task C - DFS Game
User ds14050
Language Ruby (2.7.1)
Score 500
Code Size 568 Byte
Status AC
Exec Time 352 ms
Memory 49992 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 3
AC × 34
Set Name Test Cases
Sample sample.txt, sample_2.txt, sample_3.txt
All contract_10.txt, contract_10_2.txt, contract_10_3.txt, contract_10_4.txt, contract_2.txt, contract_2_2.txt, contract_2_3.txt, contract_2_4.txt, contract_3000.txt, contract_3000_2.txt, contract_3000_3.txt, contract_3000_4.txt, contract_500.txt, contract_500_2.txt, contract_500_3.txt, contract_500_4.txt, lucky.txt, min.txt, random.txt, random_10.txt, random_2.txt, random_3.txt, random_4.txt, random_5.txt, random_6.txt, random_7.txt, random_8.txt, random_9.txt, sample.txt, sample_2.txt, sample_3.txt, uni.txt, unlucky.txt, unu.txt
Case Name Status Exec Time Memory
contract_10.txt AC 296 ms 42476 KB
contract_10_2.txt AC 306 ms 43568 KB
contract_10_3.txt AC 298 ms 42160 KB
contract_10_4.txt AC 311 ms 43972 KB
contract_2.txt AC 332 ms 44472 KB
contract_2_2.txt AC 318 ms 44704 KB
contract_2_3.txt AC 312 ms 43320 KB
contract_2_4.txt AC 312 ms 43808 KB
contract_3000.txt AC 298 ms 43456 KB
contract_3000_2.txt AC 281 ms 42180 KB
contract_3000_3.txt AC 287 ms 42832 KB
contract_3000_4.txt AC 291 ms 43476 KB
contract_500.txt AC 290 ms 43988 KB
contract_500_2.txt AC 277 ms 41852 KB
contract_500_3.txt AC 283 ms 43184 KB
contract_500_4.txt AC 291 ms 43512 KB
lucky.txt AC 296 ms 43640 KB
min.txt AC 62 ms 14048 KB
random.txt AC 125 ms 22136 KB
random_10.txt AC 313 ms 44144 KB
random_2.txt AC 207 ms 32728 KB
random_3.txt AC 80 ms 15944 KB
random_4.txt AC 325 ms 44184 KB
random_5.txt AC 141 ms 22648 KB
random_6.txt AC 158 ms 25164 KB
random_7.txt AC 109 ms 21448 KB
random_8.txt AC 116 ms 21916 KB
random_9.txt AC 317 ms 43800 KB
sample.txt AC 63 ms 14320 KB
sample_2.txt AC 59 ms 14092 KB
sample_3.txt AC 62 ms 14240 KB
uni.txt AC 337 ms 49992 KB
unlucky.txt AC 312 ms 43576 KB
unu.txt AC 352 ms 46776 KB


2025-04-05 (Sat)
03:28:48 +00:00