Submission #61841606


Source Code Expand

Copy
N,M,*P = $<.read.split.map(&:to_i)
B = ((1..M).bsearch{|b|
m = 0
P.any?{|p|
k = (b/p+1)/2
M<m += k*k*p
}
}||1)-1
#p [:B,B]
K = P.map{|p| (B/p+1)/2 }
#p K
m = P.zip(K).sum{|p,k| k*k*p }
P.zip(K).map.with_index{|(p,k),i| [(k+k+1)*p,i] }.sort_by{|kkp,|kkp}.each{|kkp,i|
if m+kkp<=M
m += kkp
K[i] += 1
end
}
#p K
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
N,M,*P = $<.read.split.map(&:to_i)

B = ((1..M).bsearch{|b|
	m = 0
	P.any?{|p|
		k = (b/p+1)/2
		M<m += k*k*p
	}
}||1)-1
#p [:B,B]
K = P.map{|p| (B/p+1)/2 }
#p K

m = P.zip(K).sum{|p,k| k*k*p }
P.zip(K).map.with_index{|(p,k),i| [(k+k+1)*p,i] }.sort_by{|kkp,|kkp}.each{|kkp,i|
	if m+kkp<=M
		m += kkp
		K[i] += 1
	end
}
#p K
p K.sum

Submission Info

Submission Time
Task E - Square Price
User ds14050
Language Ruby (ruby 3.2.2)
Score 475
Code Size 354 Byte
Status AC
Exec Time 542 ms
Memory 58824 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 475 / 475
Status
AC × 2
AC × 26
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt
All 00_sample_00.txt, 00_sample_01.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_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
Case Name Status Exec Time Memory
00_sample_00.txt AC 42 ms 17232 KB
00_sample_01.txt AC 44 ms 17392 KB
01_random_00.txt AC 536 ms 54052 KB
01_random_01.txt AC 542 ms 56172 KB
01_random_02.txt AC 521 ms 56236 KB
01_random_03.txt AC 518 ms 56164 KB
01_random_04.txt AC 520 ms 56084 KB
01_random_05.txt AC 524 ms 56080 KB
01_random_06.txt AC 528 ms 56116 KB
01_random_07.txt AC 540 ms 56168 KB
01_random_08.txt AC 538 ms 56176 KB
01_random_09.txt AC 527 ms 56072 KB
01_random_10.txt AC 86 ms 19840 KB
01_random_11.txt AC 446 ms 44284 KB
01_random_12.txt AC 76 ms 19164 KB
01_random_13.txt AC 130 ms 25092 KB
01_random_14.txt AC 331 ms 40568 KB
01_random_15.txt AC 507 ms 58824 KB
01_random_16.txt AC 279 ms 32208 KB
01_random_17.txt AC 180 ms 30576 KB
01_random_18.txt AC 403 ms 42524 KB
01_random_19.txt AC 451 ms 43952 KB
01_random_20.txt AC 403 ms 54552 KB
01_random_21.txt AC 509 ms 54408 KB
01_random_22.txt AC 43 ms 17300 KB
01_random_23.txt AC 43 ms 17304 KB


2025-04-27 (Sun)
14:17:44 +00:00