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

Автор StellarSpecter, история, 20 месяцев назад, По-английски

2000F - Color Rows and Columns

Greedy: First we find which dimension is the smallest say it's x (and it's partner dimension is y), we keep colouring x until x=y-1, now we can colour y-1 twice for y-1 cost each and we will have (x-1,x) as resulting dimension. We keep doing it until we get to say (0,1) which means we have one row/column coloured for no extra cost!

We can implement this strategy by using some visited array to keep marking indices etc. I have done the implementation but it's failing on some random testcase. I can't even dry run why is it not working. Can anyone help me with it by providing a testcase where greedy fails and why DP is the way to go.

Tagging my fav ppl (if you're free, please respond)

Fav. LGM neal. (sorry, tourist doesn't count)

Fav. IGM Shayan

Fav. IM aryanc403

Fav. CM stefdasca

Fav. Expert jatrophalouvre

Thanks for your time for reading it.

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

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

You should've tagged Psychotic_D

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

What about this test?

2 7
2 10
3 4
»
20 месяцев назад, скрыть # |
 
Проголосовать: нравится +4 Проголосовать: не нравится

For me it became clear when the last sample testcase for the question did not work. I always got 36 instead of 35. Upon dry-testing, the greedy subroutine fails.

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

That was the approach I also implemented during the contest, but it failed on the last test case from test 1. I tried to write it step by step on a paper, and it really wasn't correct, because greedy here won't make optimal decision everytime

»
20 месяцев назад, скрыть # |
Rev. 2  
Проголосовать: нравится +13 Проголосовать: не нравится

The real reason why it doesn't work is because you can't prove it works.

You can prove that given $$$n = 1$$$, its optimal to just color as much as you can of the row/column that is closest to completion.

Proof

However you cant prove that amongst all rectangles its always optimal to start from the one where its closest to complete a row/column. If you cant find a reasoning aside from "it makes sense" you shouldn't expect it to work.