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

Автор HighHopes, история, 4 года назад, По-английски

Disclaimer: This problem is from a contest on Hackerearth(hiring for intern) held on 13th April.


I was unable to solve this problem, can anyone help how to solve it? Can it be solved greedily or we need to use some graph algo?

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

»
4 года назад, # |
Rev. 2   Проголосовать: нравится +1 Проголосовать: не нравится

The answer doesn't exceed 2. When the answer is 0, grid is already disconnected. When the answer is 1... , I don't have so good solution, but I'm glad if you read this.

this
  • »
    »
    4 года назад, # ^ |
      Проголосовать: нравится +8 Проголосовать: не нравится

    One more solution which i guess is correct:

    Spoiler
    • »
      »
      »
      4 года назад, # ^ |
        Проголосовать: нравится +9 Проголосовать: не нравится
      Correct special case
      • »
        »
        »
        »
        4 года назад, # ^ |
        Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

        Why no solution, we can replace those g's by d and the grid is disconnected.
        also the problem doesn't mention anything like NO SOLUTION.