Editorial for COI '14 #2 Kovanice
Submitting an official solution before solving the problem yourself is a bannable offence.
Let's first imagine there aren't any weighings in which both sides are equal. We will construct a graph where each weighing creates an edge . The constructed graph is a directed acyclic graph (DAG), because if we had cycles, that would mean that the test data isn't consistent.
It is clear that this graph cannot have a chain longer than because that would mean that there are more than types of coins. The coins located on the chain of length have their weight determined unambiguously and it is known that the first coin in the chain is K1
, the second K2
and so on until the coin which is KN
. The coins not located in any chain of length cannot have their weight unambiguously determined because that means there are more types of coins than the number of coins in the chain, and therefore there are more possible layouts satisfying the conditions from the chain.
Now it is also possible to process the weighings in which both sides are equal. All coins of equal weight can be combined in one node and run the previously described algorithm on this graph. It is necessary to remember which coins are in which node so we can output the result for each of them.
Comments