081. It's a Mess!

Codeforces
IDCF10269081
Time1000ms
Memory256MB
Difficulty
English · Original
Formal · Original
You have an in-home library, but its organization is a mess! Fantasy books next to non-fiction biographies, detective novels next to ancient classics, and worst of all, the author's names aren't in alphabetical order! To fix this problem, you decide to create a program that is able to divide the books into different genre groups, with the authors of the genres listed in alphabetical order. The first line will contain the number of books that are in the library, and the following lines will contain books in this format, with the author's last name as the first word, and the genre as the second word, with both being separated by a space. Output a line of string that will contain a single Genre, and the list of authors writing in that genre in alphabetical order, in this format: _: , , _ (For the order of the genres, please make sure that they are also in alphabetical order.) (It can also be assumed that all genres and authors will contain one word, but last names will have proper capitalization conventions.) ## Input The first line will contain the number of books that are in the library, and the following lines will contain books in this format, with the author's last name as the first word, and the genre as the second word, with both being separated by a space. ## Output Output a line of string that will contain a single Genre, and the list of authors writing in that genre in alphabetical order, in this format: _: , , _ [samples] ## Note (For the order of the genres, please make sure that they are also in alphabetical order.)(It can also be assumed that all genres and authors will contain one word, but last names will have proper capitalization conventions.)
**Definitions** Let $ n \in \mathbb{Z}^+ $ be the number of books. Let $ B = \{ (a_i, g_i) \mid i \in \{1, \dots, n\} \} $ be the set of book entries, where: - $ a_i \in \mathbb{S} $ is the author's last name (string with proper capitalization), - $ g_i \in \mathbb{S} $ is the genre (string). **Constraints** 1. $ n \geq 1 $ 2. Each $ a_i $ and $ g_i $ consists of a single word. **Objective** Group books by genre: for each unique genre $ g $, collect the set of authors $ A_g = \{ a_i \mid (a_i, g_i) \in B \land g_i = g \} $. Sort genres lexicographically. For each genre $ g $ in sorted order, sort $ A_g $ lexicographically. Output each genre $ g $ followed by its sorted author list in the format: $$ g: a_1, a_2, \dots, a_k $$ where $ a_1, a_2, \dots, a_k $ are the sorted authors.
API Response (JSON)
{
  "problem": {
    "name": "081. It's a Mess!",
    "description": {
      "content": "You have an in-home library, but its organization is a mess! Fantasy books next to non-fiction biographies, detective novels next to ancient classics, and worst of all, the author's names aren't in al",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10269081"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "You have an in-home library, but its organization is a mess! Fantasy books next to non-fiction biographies, detective novels next to ancient classics, and worst of all, the author's names aren't in al...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ n \\in \\mathbb{Z}^+ $ be the number of books.  \nLet $ B = \\{ (a_i, g_i) \\mid i \\in \\{1, \\dots, n\\} \\} $ be the set of book entries, where:  \n- $ a_i \\in \\mathbb{S} $ is the auth...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments