#P6930. Cluedo Accusation Readiness

    ID: 20137 Type: Default 1000ms 256MiB

Cluedo Accusation Readiness

Cluedo Accusation Readiness

In the board game Cluedo (developed in the 1940s in the United Kingdom), the goal is to deduce the three mystery cards – one person (from A to F), one weapon (from G to L), and one room (from M to U) – which represent the murderer, the murder weapon, and the location, respectively.

You are player 1. At the start you are dealt a set of cards; these cards are not part of the secret envelope. Throughout the game, suggestions are made. A suggestion consists of one card from each category (person, weapon, room). When a suggestion is made, players are asked in clockwise order (with player 1 following player 4) to show evidence if they hold any of the suggested cards.

  • If you (player 1) make a suggestion and someone shows evidence (i.e. a card), you know exactly which card was shown and can eliminate that card from being the solution.
  • If another player makes a suggestion and someone shows evidence, you do not know which card was shown unless you yourself hold one or two of the suggested cards. In that case, if exactly one of the three suggested cards is not in your hand, that card must be the one shown, and hence it is not in the envelope.
  • If you make a suggestion and no one shows evidence (responder is 0), then none of the other players hold any of the three suggested cards. Since you already know your own cards, every suggested card that you do not hold is confirmed to be in the secret envelope for its respective category.

Your task is to process the history of suggestions and evidence, and decide how close you are to being able to make a final accusation.

There are a total of:

  • 6 person cards: A, B, C, D, E, F
  • 6 weapon cards: G, H, I, J, K, L
  • 9 room cards: M, N, O, P, Q, R, S, T, U

At the beginning, any card that is not in your hand could be the secret card for its category. As you process the suggestion events, you will be able to eliminate cards that are held by some player. At the end, for each category:

  • Let p be the number of possible person cards that might be in the envelope.
  • Let w be the number of possible weapon cards.
  • Let r be the number of possible room cards.

If for every category the number of possibilities is exactly 1 then you are ready to make an accusation and you should output YES. Otherwise, output NO and the three numbers p, w, and r (in that order) separated by a space.

Deduction Rules:

  1. Initially, mark all the cards in your hand as held.
  2. For a suggestion event, the input line consists of 6 tokens:
    • The three suggested cards: one person (A–F), one weapon (G–L), and one room (M–U).
    • sender: an integer (1 to 4) indicating who made the suggestion.
    • responder: an integer (0 means no one showed evidence; otherwise the player number who provided evidence).
    • card: if sender is 1 and responder is not 0, this field contains the card that was shown; if responder is 0 then this field is '-' (a placeholder); if sender is not 1 and evidence was shown (responder ≠ 0), this field is '?' because you don’t know which card was shown.
  3. If sender == 1 (you) and evidence was shown (responder ≠ 0), mark the shown card as held.
  4. If sender != 1 and evidence was shown (responder ≠ 0), let X be the set of suggested cards that you do not hold. If |X| == 1, then that card must have been shown; mark it as held.
  5. If sender == 1 and no one showed evidence (responder == 0), then for each suggested card that you do not hold, you can conclude that card is in the envelope, confirming that category’s solution card. (Note: In a valid game, this will lead each category to have at most one confirmed card.)
  6. For other events (i.e. sender != 1 with no evidence) no deduction can be made.
  7. After processing all events, for each category:
    • If a confirmed envelope card has been deduced for that category, the number of possibilities for that category is 1.
    • Otherwise, the possibilities equal the total cards in the category minus the cards known to be held.

Output YES if every category has exactly one possibility. Otherwise, output NO and the three numbers (for person, weapon, and room, in that order) separated by a space.

inputFormat

The input is given as follows:

  1. An integer C (1 ≤ C ≤ 21), the number of cards in your hand.
  2. A line with C space‐separated characters, representing the cards in your hand.
  3. An integer S, the number of suggestion events.
  4. S lines follow, each line containing 6 tokens separated by spaces:
    • The suggested person card (an uppercase letter from A to F),
    • The suggested weapon card (an uppercase letter from G to L),
    • The suggested room card (an uppercase letter from M to U),
    • An integer sender (1 to 4) - the player who made the suggestion,
    • An integer responder (0 or 1 to 4) - 0 if no evidence was shown, otherwise the player number who showed evidence,
    • A token for the card shown. If evidence was shown by player 1, this is the card shown; if no evidence was shown, it is '-' ; if evidence was shown by another player, it is '?' (since you do not see the card).
    • </ul> </ol>

      You can assume that the input is consistent with the rules of the game.

      outputFormat

      If you have deduced exactly one possible card for each category, output YES. Otherwise, output NO followed by three integers separated by a space: the number of possible person cards, weapon cards, and room cards, in that order.

      sample

      3
      A G M
      3
      B H N 1 2 H
      C I O 2 3 ?
      D J P 3 0 -
      
      NO 5 4 8