Code Guessing
Time limit1sMemory limit1024 MB
Given Alice's two digits and the table positions of the four sorted cards, decide whether Bob's two digits are uniquely determined and print them, else -1.
- Level
Easy3 of 10
- Topics
- Brute force, Implementation, Combinatorics
- Solved
- No attempts yet
Problem
Alice and Bob are playing a board game with a deck of nine cards. For each digit between 1 and 9, there is one card with that digit on it. Alice and Bob each draw two cards after shuffling the cards, and see the digits on their own cards without revealing the digits to each other. Then Alice gives her two cards to Bob. Bob sees the digits on Alice's cards and lays all four cards on the table in increasing order by the digits. The cards are laid facing down.
Bob tells Alice the positions of her two cards. The goal of Alice is to guess the digits on Bob's two cards. Can Alice uniquely determine these two digits and guess them correctly?
Input
The input has two integers , () on the first line, giving the digits on Alice's cards. The next line has a string containing two 'A's and two 'B's, giving the positions of Alice's and Bob's cards on the table. It is guaranteed that Bob correctly sorts the cards and gives the correct positions of Alice's cards.
Output
If Alice can uniquely determine the two digits on Bob's cards, output the two digits on a single line, starting with the smaller digit. Otherwise, output -1.