SHOOTING - Editorial

@caioaao: Who will count number of test cases :stuck_out_tongue:

3 Likes

@kotsya_by Thanks for the editorial.
It will be very helpful if you can also explain:

  1. What is meant by “vertical” and “horizontal” lasers.
  2. How there can be at max 16 lasers on the grid.
  3. Is the MN complexity due to “checking whether all enemies on one side of the laser or the other side.”
    Kindly clarify them. Thanks. :slight_smile:

stop using set,there is an easier way to check if an enemy is out or not.For every enemy you cand codify the lasers down to him like this.Let’s say down to an enemy is laser number 8,then you add to the integer of the enemy 2^8.

When you want to see in O(1) if an enemy is out because of the chosen lasers(“vertical” lasers),you make & between the integer of the enemy and the chosen lasers.If the result is >0,then you know the enemy is out.

Just take and example,you should understand it easily,and that codifying is useful for a lot of problems :wink:

@dpraveen I dont take into account the number of test cases, unless when explicitly needed, cuz normally the worst case will appear in a small subset of cases, so the number of test cases is just a constant negligible factor

Unfortunately, your solution is wrong and the test data is weak. Here is one test case which makes your solution fail:

1
3 4
.EE.
ELLE
ELLE
32 Likes

I don’t think that this problem can be solved by maxflow.

  1. Need to ensure that one Laser only shoots in one direction. Although this can be circumvented by creating 3 nodes for each laser. L_top, L_left, L_right.
  2. This cannot be modeled as a maximum-bipartite matching as each enemy can be destroyed by multiple lasers.
  3. There is not way to control flow out of enemy(E).

I tried this approach during the competition and failed miserably. I was checking if maxflow >= number_of_enemies.

Can anyone explain what the editorials want to explain i am not getting it :frowning:

Laser can shoot only once?

backtracking wasnt invented yet in 2014?