Expected Error
InterviewTime limit1sMemory limit1024 MB
Given a sudo password of length n, a slip after k correct characters with probability p%, pick the strategy (continue, backspace, or restart) with the lowest expected typing time.
- Level
Easy2 of 10
- Topics
- Math, Implementation
- Solved
- No attempts yet
Problem
You are typing your password at a sudo prompt when one of your fingers slips onto a wrong key. The terminal hides the characters you type, so you cannot tell whether an extra character got in. You can finish typing the password with one of three strategies.
- Continue to type the rest of your password.
- Press backspace to delete the last character, then type the rest of your password.
- Restart typing your password from scratch.
Use these typing speed assumptions to find the best strategy.
- Typing any character of your password takes seconds.
- Pressing backspace or submitting your password takes seconds.
- Restarting requires deleting all characters, which takes seconds.
- If you submit a wrong password, it takes an additional seconds to notice the mistake and start typing at a new, empty prompt.
You are given the password length , the number of characters you typed correctly before your finger slipped, and the probability that you pressed a wrong key, which leaves you with characters. Assuming you make no further errors, determine which strategy has the lowest expected time to finish typing your password.
Input
The input consists of:
- One line with three integers , , and (, , ): the number of characters in your password, the number of characters you typed correctly before your finger slipped, and the probability percentage that you pressed a wrong key.
Output
Output one of the strings continue, backspace, or restart for the optimal strategy. It is guaranteed that the optimal strategy's expected time is at least one millisecond shorter than that of the other strategies.