Guessing Passwords

시간 제한1초메모리 제한1024 MB

요약
초록 칸 없이 각 추측의 노란 칸 수가 일정한 Wordle 색깔 정보만 주어질 때, 알파벳 크기 Sigma에서 일관된 추측 문자열들과 비밀 비밀번호를 복원한다.
난이도

보통10점 중 7점

유형
구현, 그리디, 수학, 조합론
정답자
아직 제출이 없습니다

문제

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 (1≤N,M≤1001 \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.

예제2

  1. 예제 1

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

    입력
    4 5
    GYGGY
    YGYGG
    GGYYG
    GYGGY
    16
    
    예상 출력
    Bugged!