PivotOJ

Guessing Passwords

시간 제한: 1000ms메모리 제한: 1024MB출처: NCPC 2024BOJ 32555

문제

Ingfríður is testing her new pet project website, Passwordle. The rules should be rather familiar for those who have played plenty of wordle, but let us review them here. The website picks a secret password that the user then has to guess. The password will be NN characters in length and the user will guess until they get it right, getting a higher score for fewer guesses. Each guess must be a string of NN characters. For each character in the guess, it will be coloured one of three colours. If that character matches the password character in the same position, the colour is green. If the character does not match, but that character is in the password somewhere else, the colour is yellow. Otherwise it is gray.

Ingfríður is of course very good at her own game, so she will always guess a password that could be the hidden password. That is to say her guess will always match the previous clues. Furthermore she knows her program never generates passwords with repeated characters, since that's insecure, and will incorporate this knowledge into her guesses.

You now receive some screenshots from her testing progress, but they got so terribly compressed you can only make out the colours and not the text itself. Furthermore it seems that she didn't manage to make any progress at all. She didn't get a single green square in the entire game and never found any more characters than she did in her very first guess, and quit out of frustration. So the number of yellow squares is the same on each row. Given this info, can you reconstruct a sequence of guesses she could have made? Or is it impossible and her program must be wrong? You may assume that Ingfríður never makes any mistake when playing, only when programming.

입력

The first line of the input contains two positive integers NN and MM (1N,M1001 \leq N, M \leq 100). NN is the number of characters in the password and MM is the number of guesses in the screenshot. Next there are NN lines, each with MM characters, the ii-th of which gives the colours of the ii-th guess. G denotes gray and Y denotes yellow. The number of Ys is constant across all lines. The characters are given without spaces between them. Finally there is a single line with a single positive integer Σ\Sigma (1Σ1061 \leq \Sigma \leq 10^6), giving the number of valid characters for the passwords.

출력

If there is no way to achieve the given colours print Bugged!. Otherwise print N+1N + 1 lines with MM numbers each, separated by spaces. The first NN lines should give the colouring in the input if the number ii denotes the ii-th character in the alphabet. The final and (N+1)(N+1)-st line should give a secret word that could have resulted in this sequence of guesses being valid. If there are multiple possible solutions any one of them will be accepted.

예제

예제 1

입력
3 4
GGYY
YGGY
GYYG
26
출력
3 4 2 1
1 5 6 2
7 2 1 8
2 1 9 10

예제 2

입력
4 5
GYGGY
YGYGG
GGYYG
GYGGY
16
출력
Bugged!
이 문제는 채점 준비 중입니다. 테스트 데이터가 확보되면 제출이 가능합니다.