Lockpicking
Time limit1sMemory limit1024 MB
Build a keycard that keeps the error count below N from every unknown starting state of the lock, for up to 10^7 rounds.
- Level
Hard9 of 10
- Topics
- Graph, DFS, Implementation
- Solved
- No attempts yet
Problem
The Hungarian State Treasury replaced the locking mechanism on one of their safes. This new lock can only be opened by custom keycards. The verification of a keycard follows a special protocol.
The lock has internal states numbered from to . For each from to , inclusive, there is a bit , and there are two states and associated with state . A bit is a binary digit that is either or . States and may coincide, and a state may be associated with itself.
Similarly, a keycard has states numbered from to . For each from to , bit and states and are associated with state . Hereafter, lock states and keycard states are both referred to as states.
In the verification process, the lock is paired with a keycard. Both of them can output bits and read the bits output by the other. At the start of the process, the lock is set to a specific initial state . The keycard is also set to its own initial state . They repeat the following steps at most times:
- Each of them outputs a single bit according to its current state. If the lock is in state , it outputs the bit . Analogously, the keycard outputs if it is in state .
- They read the bit that the other one output. The lock reads , and the keycard reads . If the two bits differ, they register an error.
- The devices change state based on the bit they read and the states associated with the current one. The lock enters state , and the keycard enters state .
If the number of errors ever reaches , the verification fails and the process terminates. Otherwise, if they complete iterations without registering at least errors, the verification succeeds and the lock opens.
When the lock was installed, the mechanics forgot to specify the initial state . As a result, whenever the lock is paired with a keycard, it starts in an arbitrary, unknown initial state.
Your task is to construct a keycard that can open the lock despite this mistake.
Constraints
- (for each such that )
- and (for each such that )
- (for each such that )
- and (for each such that )