시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
1 초 | 128 MB | 34 | 20 | 19 | 59.375% |
Jessie was learning about programming contests at Bessie's knee. "Do they play games?" she asked.
"Oh yes," Bessie nodded sagely. "Here's a classic."
MasterMind is a classic two player game. One of the players is the 'codemaker'; she picks a four digit secret number S (1000 <= S <= 9999). The other player is the 'codebreaker' who repeatedly guesses four digit numbers until she solves the code.
The codemaker provides feedback that comprises two integers for each codebreaker guess G_i (1000 <= G_i <= 9999). For each codebreaker guess, the codemaker's feedback comprises two integers:
The first integer C_i (0 <= C_i <= 4) specifies how many of the guess's digits are correct and in their correct location in the secret number
The second integer W_i (0 <= W_i <= 4-C_i) specifies how many of the remaining digits (i.e., those not described by C_i) are correct but in the wrong location.
For example, suppose codemaker's secret number is 2351. If codebreaker guesses 1350, the codemaker provides the feedback "2 1", since 3 and 5 are in correct locations in the number, and 1 is in the wrong location. As another example, if the secret number is 11223 (in a five-digit version of mastermind) and the guess is 12322, then the feedback would be "2 2".
Below is a sample game where the secret number is 2351:
Correct digits in correct location | Correct digits in wrong location Guess | | 3157 1 2 1350 2 1 6120 0 2 2381 3 0 2351 4 0
For this task, you are given N (1 <= N <= 100) guesses with their feedback in the middle of a game. You are asked to output the smallest four digit number which can be a candidate for codemaker's secret code (i.e., which satisfies all the constraints).
If there are no such numbers, output "NONE" (without the quotes).
4 3157 1 2 1350 2 1 6120 0 2 2381 3 0
2351