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

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

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
  • Проголосовать: не нравится

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

You should've tagged Psychotic_D

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

What about this test?

2 7
2 10
3 4
»
3 месяца назад, # |
  Проголосовать: нравится +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.

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

    I cheesed the last sample testcase by setting each value as the last and sorting by min a,b, however that failed on testcase 3

»
3 месяца назад, # |
  Проголосовать: нравится 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

»
3 месяца назад, # |
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.

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

    in order to be sure, though, shouldn't you prove that it doesn't work?

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

      To prove it doesn't work you need a counter example, he already has that. The thing I was trying to get across is that in a competition you need to find a strong reason why your algorithm works, not just implementing if you can't find a reason why it doesn't.

      Of course, you can get away with guessing on easy problems, but they're easy because they are easy to guess. For harder problems you are likely to be guessing something wrong and be wasting a bunch of time trying to figure out whether the idea or the code is wrong.