PivotOJ

Guess Who

시간 제한: 1000ms메모리 제한: 1024MB출처: ICPC Rocky Mountain Regional 2023-2024BOJ 30553

문제

Guess Who is a two-player board game in which a number of characters are uniquely identified by a set of attributes (e.g. wearing glasses), and each player attempts to guess the other player's hidden character by asking a number of yes/no questions such as "does the person wear glasses?"

In our variation of this game, there are NN characters, each of which is uniquely identified by a set of MM attributes. The value of each attribute is either YES or NO. You will be provided with a list of the characters and their attributes, together with a series of QQ questions and the corresponding responses. Your task is to determine the hidden character, if possible.

입력

Input begins with three space-separated integers NN, MM, and QQ, satisfying 1N10001 \leq N \leq 1\,000, 1M151 \leq M \leq 15, and 1QM1 \leq Q \leq M. The next NN lines each contains a string of MM characters that are either Y or N. The iith line specifies the values of the MM attributes of the iith character. Each of the next QQ lines contains an integer 1AM1 \leq A \leq M, followed by a space, followed by a single character Y or N. This indicates the question is about attribute AA, and the response that the attribute of the hidden character is YES or NO. There is at most one question for each of the attribute. At least one of the listed characters has attributes consistent with the responses of the queries.

출력

In the first line, output one of unique or ambiguous, indicating if there is a uniquely identifiable hidden character, or if there are multiple possible hidden characters.

In the case in which the hidden character is uniquely identifiable, output on the second line the index (between 1 and NN) of the hidden character. If there are multiple possible hidden characters, output on the second line the number of possible hidden characters.

예제

예제 1

입력
5 5 3
YYYYY
NNNNN
YNYNY
YYYNN
NNYYY
1 N
2 N
3 Y
출력
unique
5

예제 2

입력
5 5 3
YYYYY
NNNNN
YNYNY
YYNNN
NNNYY
1 Y
5 Y
3 Y
출력
ambiguous
2
코드를 제출하려면 로그인하세요.