Editorial for Max's Anger Contest Series 1 P4 - Greedily Gamboling
Submitting an official solution before solving the problem yourself is a bannable offence.
Author:
Subtask 1
It suffices to run Dijkstra's algorithm from to .
Time Complexity:
Subtask 2
Realize that since toggles can only be used once, states of what toggles have been used can be represented with a bitmask.
Now, for each node and the current bitmask, consider all edges that connect this node and bitmask through all supersets of the current bitmask: if the current bit is on in the superset but not for the original bitmask and the current edge weight has that bit on, subtract it from the current weight. Once all bits are considered, push that node and new bitmask into the priority queue.
Finally, output the shortest distance from to using none, some, or all of the toggles.
Time Complexity:
Note that it is possible to achieve by iterating only over the bitmasks that are supersets of the current bitmask without considering any extra masks.
Exercise
Consider how you could optimize the full solution to have a smaller power by reducing the base for the number of edges.
Implement and submit to this harder version with increased constraints on .
Comments
Link to harder version just gives error "No such problem; Could not find a problem with the code "macs1p4hard"."
The problem has been published. I have been busy and just got around to buffing the data—apologies for the inconvenience.