Help with Google Code Jam 2018 Round 1A Problem C

Правка en2, от Silence_for_Melody, 2018-04-17 08:16:39

Hi Codeforces.

On friday I participated in the round 1A of the GCJ but I could not pass the third problem. Even the easy set test. Here are my two codes.

PROBLEM

Easy case LINK. Full case LINK.

In the easy one, I just did what the editorial said. However, I got WA repeatedly (15 submissions).

For the full set, my idea is the following. First rest from P the perimeter of all the rectangles and now I have P'. Now, each rectangle i add to the answer 0 if it is not cut, or a number in range [ L[i], R[i] ] where L[i] = 2 * min (W[i], H[i]) and R[i] = 2 * hypot (W[i], H[i]) if is cut. The idea is to choose a subset of the rectangles whom will be cut and the sum of additional perimeters must not exceed P'.

Now, each subset j generates an interval [ L_subset[j], R_subset[j] ]. However, these intervals will always start (left side value) with at most 250 * 100 (maximum side length and maximum quantity of rectangles). Therefore, I did a DP where DP[i] is the maximum right side of an interval for the left side be exactly i.

Start DP[i] = -INF
DP[0] = 0
FOR i in range(0, N):
	FOR leftside in range(0,25001)
		DP[leftside] = max (DP[leftside] , DP[leftside – L[i] ] + R[i] ) 

Now, for each DP[i] for i <= P' I checked if DP[i] >= P', then the answer is P as this could be reached. Otherwise, the answer is max DP[i] for i <= P' plus the sum of perimeters of all rectangles.

The complexity of this idea is 100 * 100 * 250. Could give TLE, I don't know because the system always gave me WA.

I spend all the weekend tring to find out why my codes gave me WA, now I need your help. Many thanks

Теги gcj

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en2 Английский Silence_for_Melody 2018-04-17 08:16:39 111
en1 Английский Silence_for_Melody 2018-04-17 07:26:59 1779 Initial revision (published)