F. Frustrating Game

Codeforces
IDCF10152F
Time1000ms
Memory256MB
Difficulty
English · Original
Formal · Original
The magician Alice is playing a game. Alice has N balls in a row, consists of red balls and blue balls. For convenience, the balls are numbered 1 to N from left to right. Her goal is to transform all balls into White by casting magic spells. In a single spell, Alice can choose exactly R red balls and B blue balls at the same time, and then cast a spell on them, so all these R + B chosen balls will become white balls. However, there is a restriction: As some magical power may remains in the white balls, Alice cannot perform spells when there exists at least one white ball located between the leftmost chosen ball and the rightmost chosen ball. For instance, if Alice balls 2, 6 and 7 have became white balls by previous spells, she cannot choose the set of balls {3, 8, 9} in a single spell as there exist a white ball numbered 5 between them. Similarly, single spell on balls {1, 3, 4}, {3, 4, 9} or {1, 9, 10} are invalid, while single spell on balls {3, 4, 5} or {8, 9, 10} are valid. As Alice has spent more than hundred of years to achieve the goal and end up in failures, she is very frustrated. So, she promised that she will teach her magic skills to the one who can solve this frustrating game. Nothing is more appealing than having an opportunity to learn magic! So you are trying to help Alice to achieve the goal. The first line contains 3 positive integers, N, R and B. (R, B ≥ 1, 1 ≤ R + B ≤ N ≤ 105) The second line contains a string S, consisting of N characters _R_ (red) and _B_ (blue). The i-th character is the color of the i-th ball from the left. If it is impossible to achieve the goal, output _NO_ on the first line. Otherwise, output _YES_, followed by an integer S on the second line – the number of spells (S) you would like to cast. In the next S lines, each should indicate a spell with R + B integers, representing the indices of the balls you have selected for this spell. You can output the indices in arbitrary order within the same line. Please note that the spells should be printed in their *chronological order*. If there are more than one solution, you can output any of them. In the first sample, the initial state is as follow: After casting the first spell: And after the second spell: And the final state: In the second sample, the initial state is as follow: In the third sample, the initial state is as follow: After casting the first spell: And at last: ## Input The first line contains 3 positive integers, N, R and B. (R, B ≥ 1, 1 ≤ R + B ≤ N ≤ 105)The second line contains a string S, consisting of N characters _R_ (red) and _B_ (blue). The i-th character is the color of the i-th ball from the left. ## Output If it is impossible to achieve the goal, output _NO_ on the first line. Otherwise, output _YES_, followed by an integer S on the second line – the number of spells (S) you would like to cast. In the next S lines, each should indicate a spell with R + B integers, representing the indices of the balls you have selected for this spell. You can output the indices in arbitrary order within the same line.Please note that the spells should be printed in their *chronological order*. If there are more than one solution, you can output any of them. [samples] ## Note In the first sample, the initial state is as follow:After casting the first spell:And after the second spell:And the final state:In the second sample, the initial state is as follow:In the third sample, the initial state is as follow:After casting the first spell:And at last:
**Definitions** Let $ N, R, B \in \mathbb{Z}^+ $ with $ 1 \leq R + B \leq N \leq 10^5 $. Let $ S \in \{R, B\}^N $ be a string representing the initial colors of $ N $ balls indexed from $ 1 $ to $ N $. Let $ W \subseteq \{1, \dots, N\} $ be the set of white balls (initially empty). A spell is a subset $ T \subseteq \{1, \dots, N\} \setminus W $ such that: - $ |T \cap \{i \mid S[i] = R\}| = R $, - $ |T \cap \{i \mid S[i] = B\}| = B $, - The interval $ [\min T, \max T] $ contains no element of $ W $ (i.e., no white ball lies strictly between the leftmost and rightmost chosen ball). **Constraints** 1. $ R, B \geq 1 $ 2. $ R + B \leq N \leq 10^5 $ 3. Each spell must satisfy the above conditions. 4. After all spells, $ W = \{1, \dots, N\} $. **Objective** Determine whether there exists a sequence of spells (in chronological order) such that all balls become white. - If impossible: output `NO`. - If possible: output `YES`, followed by the number of spells $ s $, then $ s $ lines each containing $ R + B $ distinct indices (in any order) of the balls selected in each spell.
API Response (JSON)
{
  "problem": {
    "name": "F. Frustrating Game",
    "description": {
      "content": "The magician Alice is playing a game. Alice has N balls in a row, consists of red balls and blue balls. For convenience, the balls are numbered 1 to N from left to right. Her goal is to transform all ",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10152F"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "The magician Alice is playing a game. Alice has N balls in a row, consists of red balls and blue balls. For convenience, the balls are numbered 1 to N from left to right. Her goal is to transform all ...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ N, R, B \\in \\mathbb{Z}^+ $ with $ 1 \\leq R + B \\leq N \\leq 10^5 $.  \nLet $ S \\in \\{R, B\\}^N $ be a string representing the initial colors of $ N $ balls indexed from $ 1 $ to $...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments