Guess Who

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

요약
N개 문자의 속성 문자열과 Q개의 속성 응답이 주어질 때, 모든 응답과 일치하는 문자 수를 세어 unique 또는 ambiguous를 판별한다.
난이도

쉬움10점 중 3점

유형
배열, 구현, 완전 탐색
정답자
아직 제출이 없습니다

문제

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 1≤N≤1,0001 \leq N \leq 1\\,000, 1≤M≤151 \leq M \leq 15, and 1≤Q≤M1 \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 1≤A≤M1 \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.

예제2

  1. 예제 1

    입력
    5 5 3
    YYYYY
    NNNNN
    YNYNY
    YYYNN
    NNYYY
    1 N
    2 N
    3 Y
    
    예상 출력
    unique
    5
    
  2. 예제 2

    입력
    5 5 3
    YYYYY
    NNNNN
    YNYNY
    YYNNN
    NNNYY
    1 Y
    5 Y
    3 Y
    
    예상 출력
    ambiguous
    2