#P7006. Kabaleo Lite Guaranteed Win
Kabaleo Lite Guaranteed Win
Kabaleo Lite Guaranteed Win
Kabaleo Lite is a board game played on a board consisting of several stacks. Each stack has a visible chip color (only the top chip is seen). Every player has a hidden target color and a set of colored chips. On his turn, a player picks one chip from his set and places it on any stack, thereby recoloring that stack to the chip's color.
After the last turn, the number of stacks showing each color is counted. Let \( f(x) \) be the frequency of color \(x\). The winning color is the one with the unique maximum frequency. The player whose target color matches the winning color wins; otherwise, if no player has that target or if the maximum frequency is shared by more than one color, the game ends in a draw.
You are about to play your last chip. All opponents also have exactly one chip remaining; their chip colors are publicly known though their target colors are hidden. Since you do not know the opponents' target colors and cannot predict their moves, your move must guarantee that the final winning color will be your target color regardless of how the opponents play.
Your move consists of selecting a stack (indexed from 1 to \(n\)) on which to place your chip. When you place your chip, that stack’s color is changed to the color of your chip. Formally, let the board initially have frequencies \( f(x) \) for each color \(x\). When you choose a stack with current color \(p\>:
- If your chip color, denoted by \(X\), is different from \(p\), then the new frequency is:
\( f'(X) = f(X) + 1 \) and \( f'(p) = f(p) - 1 \); all other colors remain the same. - If \(p = X\) then the board remains unchanged.
After your move, each opponent will play their chip. Denote your target color by \(T\) and let the opponents have fixed chip colors. For each opponent whose chip color is not \(T\), if they choose to play on a stack showing \(T\) they will reduce \(T\)'s count. Let \(d\) be the number of opponents with chip color different from \(T\), and let \(O_Y\) be the number of opponents with chip color \(Y\) (for any color \(Y\)). In the worst case, opponents can reduce the frequency of \(T\) to
[ T_{final} = f'(T) - \min(f'(T), d). ]
Similarly, for any color \(Y \neq T\), opponents can boost its final count by at most \(O_Y\), thus the worst–case final count for color \(Y\) is
[ f_Y = f'(Y) + O_Y. ]
Your move guarantees your victory if and only if the following condition holds for every color \(Y \neq T\):
[ f'(T) - \min(f'(T), d) > f'(Y) + O_Y. ]
Given the board state, the opponents' chip colors, your target color \(T\), and your chip color \(X\), determine all stack indices on which if you place your chip the above condition is satisfied, regardless of how opponents play.
inputFormat
The input consists of 6 lines:
- An integer \(n\) \( (1 \leq n \leq 10^5)\), the number of stacks.
- \(n\) space–separated strings representing the colors of the stacks.
- An integer \(k\) \( (0 \leq k \leq 10^5)\), the number of opponents.
- \(k\) space–separated strings representing the opponents' chip colors.
- A string \(T\), your target color.
- A string \(X\), the color of your (last) chip.
Colors are nonempty strings without spaces.
outputFormat
Output a single line containing the 1–indexed positions of stacks (in increasing order) on which if you place your chip, you are guaranteed to win the game. If no move guarantees victory, output an empty line.
sample
3
red blue blue
1
blue
red
red