Codeforces Round #273 Editorial (Unfinished)

Revision en6, by xuanquang1999, 2015-06-17 04:34:48

Hello everyone. I have noticed the absence of round 273's editorial, so I decided to write one. This is the first time I write an editorial, so hope everyone like this!

I didn't know how to solve C and E yet, so it would be appreciated if someone help me with these problems.

Also, how to use LaTex in codeforces? I want to use this so my editorial would be more clear to read.

UDP: Actually, there's a (well-hidden) tutorial for this round, but it's written in Russian. If you can read Russian, click here.

A — Initial Bet

Since the coin only pass from this player to other player, the coins sum of all player won’t change in the game. That mean, we’ll have 5*b = c1+c2+c3+c4+c5. We’ll put sum = c1+c2+c3+c4+c5. So, if sum is divisible by b, the answer will be sum/b. Otherwise, the answer doesn’t exist.

Be careful with the case 0 0 0 0 0 too, since b > 0, answer doesn’t exist in this case.

My solution: 11607374

Complexity: O(1)

B — Random Teams

If a team have a participants, there will be a*(a-1)/2 pairs of friends formed.

For the minimum case, the participants should be unionly – distributed in all the team. More precisely, each team should not have more than one contestant compared to other team. Suppose we’ve already had n div m contestant in each team, we’ll have n mod m contestant left, we now should give each contestant left in first n mod m teams.

For example, with the test 8 3, we’ll first give all team 8 div 3 = 2 contestants, the result now is 2 2 2. We’ll have 8 mod 3 = 2 contestants left, we should each contestant in the first and the second team, so the final result is: 3 3 2.

The maximum case is more simple, we should give only give one contestant in first m-1 teams, and give the last team all the contestant left. For example with above test, the result is 1 1 6.

Since number of the contestant in one team can be 10^9, the maximum numbers of pairs formed can be 10^18, so we should use int64 (long long in c++) to avoid overflow.

My solution: 11607784

Complexity: O(1)

C — Table Decorations

Unfinished...

D — Red-Green Towers

For more convenient, we’ll call a function trinum(x) = (x*(x+1))/ 2. First, we’ll find h, the maximum height possible of the tower. We know that h <= trinum(l+r). Since (l+r) <= 2*10^5, h <= 631, so we can just use a brute-force to fill this value.

Now, the main part of this problem, which can be solved by using dynamic programming. We’ll f[ih, ir] the number of towers that have height ih, can be built from ir red block and trinum(ih)-ir green blocks.

For each f[ih, ir], there’s two way to reach it:

  • Add ih red block. This can only be done if ih <= ir <= min(r, trinum(ih)). In this case, f[ih, ir] = f[ih, ir] + f[ih-1, ir-ih].

  • Add ih green block. This can only be done if max(0, trinum(ih)-g) <= ir <= min(r, trinum(ih-1)). In this case, f[ih, ir] = f[ih, ir] + f[ih-1, ir-ih].

The answer to this problem is sum of all f[h, ir] with 0 <= ir <= r.

We will probably get MLE now...

MLE solution: 11600887

How to improve the memory used? We'll see that all f[ih] can only be affected by f[ih-1], so we'll used two one-dimension arrays to store the result instead of a two-dimension array. The solution should get accepted now.

Accepted solution: 11600930

Complexity: O(r*sqrt(l+r))

E — Wavy numbers

Unfinished...

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en14 English xuanquang1999 2015-06-27 16:28:57 5 Tiny change: 'ng. We’ll `f[ih, ' -> 'ng. We’ll call `f[ih, '
en13 English xuanquang1999 2015-06-27 16:27:56 4 Tiny change: 'ossible `(0, 1, 2)` group l' -> 'ossible `(1, 1, 1)` group l'
en12 English xuanquang1999 2015-06-27 16:26:34 8
en11 English xuanquang1999 2015-06-17 06:50:25 1355 Tiny change: '], a[1])`. At this po' -
en10 English xuanquang1999 2015-06-17 04:52:15 4 Tiny change: 'orce to fill this valu' -> 'orce to find this valu'
en9 English xuanquang1999 2015-06-17 04:51:44 2 Tiny change: '1))/ 2`.\nFirst, w' -> '1))/ 2`.\n\nFirst, w'
en8 English xuanquang1999 2015-06-17 04:40:16 8
en7 English xuanquang1999 2015-06-17 04:36:51 67
en6 English xuanquang1999 2015-06-17 04:34:48 4 Tiny change: ' read.\n\nUDP: Actually,' -> ' read.\n\n**UDP:** Actually,'
en5 English xuanquang1999 2015-06-17 04:34:29 190
en4 English xuanquang1999 2015-06-17 03:58:14 2 Tiny change: ' formed.\nFor the ' -> ' formed.\n\nFor the '
en3 English xuanquang1999 2015-06-16 18:02:39 4
en2 English xuanquang1999 2015-06-16 18:01:56 2 Tiny change: 'nfinished.\n' -> 'nfinished...\n'
en1 English xuanquang1999 2015-06-16 18:01:26 3562 Initial revision (published)