#K55622. Mastermind Game Simulation

    ID: 30017 Type: Default 1000ms 256MiB

Mastermind Game Simulation

Mastermind Game Simulation

This problem simulates a variant of the classic Mastermind game. The secret code consists of L digits. For each guess, you must provide feedback consisting of two numbers:

  • x: the number of digits that are in the correct position.
  • y: the number of correct digits, but located in the wrong positions.

If a guess exactly matches the secret code (i.e. \(x = L\)), output an extra line: Congrats! You've broken the code in M attempts. where M is the number of attempts taken. Otherwise, if the maximum number of attempts is reached without guessing the code correctly, output a final line: Sorry! You've used all attempts.

The feedback is computed as follows:

First, count the number of positions \(i\) such that the \(i^{th}\) digit of the guess equals the \(i^{th}\) digit of the secret code. Then, for the remaining unmatched digits, count the number of digits in the guess that also appear in the secret code in different positions (each digit may be counted only once).

inputFormat

The input is read from stdin and has the following format:

L K N
C
G1
G2
...
GN

Where:

  • L is the length of the secret code.
  • K is the maximum number of allowed attempts.
  • N is the number of guesses provided.
  • C is the secret code (a string of L digits).
  • G1, G2, ..., GN are the guess strings.

Note: The game stops processing further guesses if the secret is correctly guessed or if K attempts have been made.

outputFormat

The output should be written to stdout and includes:

  • For each processed guess, output a line with two integers x y where x is the count of digits in the correct position, and y is the count of correct digits but in wrong positions.
  • If a guess exactly matches the secret code (i.e. x = L), output an additional line: Congrats! You've broken the code in M attempts.
  • If the maximum number of attempts K is reached without a correct guess, output a final line: Sorry! You've used all attempts.
## sample
4 10 4
1234
5678
1235
1243
1234
0 0

3 0 2 2 4 0 Congrats! You've broken the code in 4 attempts.

</p>