Блог пользователя malachi_toney_goat

Автор malachi_toney_goat, история, 6 лет назад, По-английски

Hello everyone! At the time I am writing this, there is still no editorial for Round #662. I did very well on this contest and I think my solutions are interesting, so hopefully this can help some people.

1393A - Rainbow Dash, Fluttershy and Chess Coloring:

Problem A

Code (Java): 89214023

1393B - Applejack and Storages:

Problem B

Code (Java): 89220791

1393C - Pinkie Pie Eats Patty-cakes

Problem C

Code (Java): 89231755

1393D - Rarity and New Dress

Problem D

Code (Java): 89257786

  • Проголосовать: нравится
  • +229
  • Проголосовать: не нравится

»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Auto comment: topic has been updated by malachi_toney_goat (previous revision, new revision, compare).

»
6 лет назад, скрыть # |
 
Проголосовать: нравится +11 Проголосовать: не нравится

golions orz

»
6 лет назад, скрыть # |
 
Проголосовать: нравится +55 Проголосовать: не нравится

Great solutions! However, there exists a

shorter solution for D.
»
6 лет назад, скрыть # |
← Rev. 4  
Проголосовать: нравится +24 Проголосовать: не нравится

Nice work! I have an alternate solution for B:

Note that since $$$1$$$ $$$\leq$$$ $$$a_i$$$ $$$\leq$$$ $$$10^5$$$, and similarly for $$$x$$$, we can store the frequencies of each plank length in an array aptly named $$$freq$$$, and increase/decrease it as we gain/remove plank lengths of that type.

We can store the amount of lengths that have frequencies of $$$2s$$$ and $$$4s$$$ in separate variables, with each stick's frequency contributing $$$\lfloor{\frac{freq_i}{2}}\rfloor$$$ and $$$\lfloor{\frac{freq_i}{4}}\rfloor$$$ respectively. Note that the amount of $$$2s$$$ and $$$4s$$$ aren't mutually exclusive, and must be accounted for at the end.

After each operation, we must check whether the number of $$$2s$$$ and $$$4s$$$ are changed. This can be done easily by checking:

  • if $$$freq_i$$$ is increased and is now equal to $$$0$$$ $$$(mod$$$ $$$2)$$$, then the number of $$$2s$$$ is increased.
  • if $$$freq_i$$$ is increased and is now equal to $$$0$$$ $$$(mod$$$ $$$4)$$$, then the number of $$$4s$$$ is increased.
  • if $$$freq_i$$$ is decreased and is now equal to $$$1$$$ $$$(mod$$$ $$$2)$$$, then the number of $$$2s$$$ is decreased.
  • if $$$freq_i$$$ is decreased and is now equal to $$$3$$$ $$$(mod$$$ $$$4)$$$, then the number of $$$4s$$$ is decreased.

This is because when an integer is increased from $$$k-1$$$ $$$(mod$$$ $$$k)$$$ to $$$0$$$ $$$(mod$$$ $$$k)$$$, it is divisible an "extra" time when performing floor division. The opposite is also true for when an integer is decreased from $$$0$$$ $$$(mod$$$ $$$k)$$$ to $$$k-1$$$ $$$(mod$$$ $$$k)$$$.

Finally, to answer each query, we must check if both $$$fours$$$ $$$\geq$$$ $$$1$$$, and $$$twos - 2$$$ $$$\geq$$$ $$$2$$$. This is to account for the planks used for the squares, the $$$4s$$$ being included in the number of $$$2s$$$. If this condition is true, we print "Yes", otherwise "No".

A link to my submission (C++)

»
6 лет назад, скрыть # |
← Rev. 2  
Проголосовать: нравится +17 Проголосовать: не нравится

Nice solutions!

I had an alternate approach for D, which I thought was interesting even if it might not be the most elegant.

My idea
  • »
    »
    6 лет назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    Is this idea managable to pass TL. I thought to implement this idea then saw TL 1 second and gave up.

  • »
    »
    6 лет назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится
    I had the same idea, though I used DP instead
»
6 лет назад, скрыть # |
 
Проголосовать: нравится +3 Проголосовать: не нравится

malachi_toney_goat Can you mention the binary_search + priority_queue solution that people have solved it with. Intuitively, I thought of that solution but couldn't come up with it. Hope you explain it.

»
6 лет назад, скрыть # |
← Rev. 2  
Проголосовать: нравится +5 Проголосовать: не нравится

You can check out my video solutions (A — D) here:

https://youtu.be/NMbqtVdVZqI

»
6 лет назад, скрыть # |
← Rev. 4  
Проголосовать: нравится 0 Проголосовать: не нравится

I solved A by simply finding a pattern:

3 -> 2
4 -> 3
5 -> 3
6 -> 4
 ...

My approach for B was to keep a map and then have three lists: pairs of same numbers (pair), quadruplets of same numbers (quad), and a list of numbers with more than 7 occurrences (many). Then there are three cases to check, using just one element from the "many" list to make two squares right off the bat, using two elements from the "quad" list to make two squares, and finally using one element from the "pair" and one element from the "quad" list to make a rectangle and a square. One thing to keep track of was making sure that you don't use the same number more than it can be used, but you can just do some simple conditional checking to account for that.

I did C by binary searching for the answer. Each time, I would do a validity check by maintaining a queue to keep track of the "unusable" ones. I would loop through each of the n spots and remove and add from the unusable accordingly and then always put the maximum occurrence number. Then, if the map ever turns empty, then return "not valid".

IMPLEMENTATIONS [JAVA] (Might be a bit messy as I am not the best implementer)

Problem A
Problem B
Problem C
»
6 лет назад, скрыть # |
 
Проголосовать: нравится +3 Проголосовать: не нравится

can we apply binary search in C??

»
6 лет назад, скрыть # |
 
Проголосовать: нравится +6 Проголосовать: не нравится

The explanation of C is daaam good! Thank you for doing the hard work

»
6 лет назад, скрыть # |
 
Проголосовать: нравится +6 Проголосовать: не нравится

thank you brother for the solutions :)

»
6 лет назад, скрыть # |
 
Проголосовать: нравится +6 Проголосовать: не нравится

Mindblowing explanation for problem C kudos

»
6 лет назад, скрыть # |
 
Проголосовать: нравится +5 Проголосовать: не нравится

Problem C Explaination is MIND_BLOWING
Thanks malachi_toney_goat

»
6 лет назад, скрыть # |
 
Проголосовать: нравится +6 Проголосовать: не нравится

upperleft[k][j]=min(upperleft[k−1][j],upperleft[k][j−1]) i think a +1 is missing here

»
6 лет назад, скрыть # |
← Rev. 2  
Проголосовать: нравится +5 Проголосовать: не нравится

In problem D, I considered the rhombus as two triangles: left and right.
For each cell $$$(i,j)$$$, I calculated two values:

  • $$$b_{i,j}$$$ = Max size of the left triangle if this cell is the centre of the rhombus
  • $$$c_{i,j}$$$ = Max size of the right triangle if this cell is the centre of the rhombus

Then, $$$m_{i,j}$$$ = $$$min(b_{i,j},c_{i,j})$$$ is the max size of a rhombus centered in this cell.
The final answer is the sum of all $$$m_{i,j}$$$.

To calculate $$$b_{i,j}$$$ and $$$c_{i,j}$$$, we need:

  • $$$up_{i,j}$$$ = Number of cell with same color above this cell
  • $$$dn_{i,j}$$$ = Number of cell with same color below this cell
  • $$$a_{i,j}$$$ = $$$min(up_{i,j},dn_{i,j})$$$

Then, $$$b_{i,j}$$$ and $$$c_{i,j}$$$ can be calculated easily using $$$a_{i,j}$$$ and dynamic programming:

  • $$$b_{i,j}$$$ = $$$min(a_{i,j},b_{i,j-1})+1$$$
  • $$$c_{i,j}$$$ = $$$min(a_{i,j},c_{i,j+1})+1$$$

This solution includes calculations of several arrays, but each of them can be calculated using simple iteration.

My submission

»
6 лет назад, скрыть # |
← Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

Why is not it enough to have just 2 counters to solve problem B? oO

I have solved the problem this way and the editorial slightly confused me.

»
6 лет назад, скрыть # |
 
Проголосовать: нравится +6 Проголосовать: не нравится

You missed adding 1 in the DP update of last solution.

»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Auto comment: topic has been updated by malachi_toney_goat (previous revision, new revision, compare).

»
6 лет назад, скрыть # |
 
Проголосовать: нравится +6 Проголосовать: не нравится

This editorial was far better than codeforces editorial thanks for this editorial :)

»
6 лет назад, скрыть # |
← Rev. 2  
Проголосовать: нравится +3 Проголосовать: не нравится

My Proof for DIV2 C,extending your logic

Let us assume that there are max-1 boxes and we have to fill them with numbers, and we have to maximize the size of the smallest box, let us first ensure that size of all boxes are 1, we have a list of frequences say cnt1 , cnt2 , ... but none of these are greater than the number of boxes so let us distribute the first number equally among boxes, if we run out of the first number, let us take the next number and start distributing them equally ( i.e one number per box), by the time we complete the first round we would have exhausted a few numbers, and no box is empty now, size of each box is 1 and we would have used max-1 numbers it reduces to the same problem again, so we can proceed with the same algorithm ,no 2 numbers in the same box will be identical and we can always rearrange numbers within a box to ensure they are max apart.

»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Better than official

»
6 лет назад, скрыть # |
 
Проголосовать: нравится +6 Проголосовать: не нравится

Better explanations than the original editorial. Especially in problem B. Thanks a ton for this. If someone wants implementation of the above in C++, here is my solution.

93437519

»
6 лет назад, скрыть # |
 
Проголосовать: нравится +6 Проголосовать: не нравится

Very good editorial.Thanks a lot brother

»
4 года назад, скрыть # |
 
Проголосовать: нравится +5 Проголосовать: не нравится

Thanks, Your solution for C is better than original editorial's sol.