Computer Dialogue
Time limit1sMemory limit128 MB
Given file names split into name and extension parts, simulate the alternating 'I don't know' messages between two clients and list files still possible after M messages.
- Level
Medium7 of 10
- Topics
- Simulation, Hash map, Implementation, String
- Solved
- No attempts yet
Problem
Three computers are connected by a network: one is a server and the other two are clients. The server stores several files, each with a distinct full name. A full name has two parts, a name and an extension, written as name.extension. Both clients know the full names of every file on the server.
The server chooses one file and sends the name part of that file to one client and the extension part to the other client. The two clients then try to work out which file was chosen (that is, its full name), but they may communicate only in a very restricted way. They take turns exchanging messages, and the only thing a client may ever say is "I don't know the full file name." A client sends this message only when it still cannot determine the full name. The client that received the name part always waits for the other client (the one holding the extension) to speak first. The exchange continues until one client learns the full name or the two of them give up.
Suppose you know every full file name on the server and you overhear the conversation. Given the number of messages exchanged, determine which files could still have been the one chosen by the server. Such files are called candidate files.
Input
The first line contains two integers and separated by a space. () is the number of files on the server, and () is the number of "I don't know" messages the clients exchanged.
Each of the next lines contains one full file name in MS-DOS 8.3 style name.extension, where both the name and the extension consist only of uppercase letters (A–Z) and digits (0–9). The name has between 1 and 8 characters; the extension has at most 3 characters and may be empty. If the extension is empty, the separating dot may be omitted (so both FILEID. and LICENCE are valid). Every full file name appears at most once.
Output
On the first line, print the number of candidate files (print 0 if there are none). Then print the full name of each candidate file on its own line. The candidates must appear in the same order and with exactly the same spelling as in the input: if the separating dot was omitted in the input, omit it in the output too, and vice versa. Do not print any file more than once.