Alice and Bob are playing a game on a binary string of length .
Alice wants to make the number of substrings
01 and 10 equal, and
both counts must be non-zero.
Formally, let
denote the number of indices
() such that
and
, and similarly let
denote the number of indices
() such that
and
.
Alice would like for
and
to both hold.
Bob, on the other hand, wants to prevent Alice from achieving this condition.
The players take turns alternately, with Alice
going first.
In each turn, the current player can remove
exactly one character from either the
beginning or the end of the string.
The game ends immediately when the string becomes empty or when Alice's desired condition () is satisfied.
If Alice can make the number of
01 and 10 substrings
equal (and both non-zero), she wins.
Otherwise, if Bob can prevent this condition
until the string becomes empty, Bob wins.
In particular, if the initial string satisfies
the required condition, Alice wins
immediately, without even having to make a
move.
Determine the winner of the game if both players play optimally.
0 and 1.
For each test case, output a single string —
Alice if Alice wins the game,
or Bob if Bob wins the game.
You may print each character of the string
in uppercase or lowercase (for example, the
strings BOB, bOb,
bob, and boB will
all be treated as identical).
4 3 000 3 010 4 0001 4 0101
Bob Alice Bob Alice
Test case
:
We have
for the initial string.
No matter what the players do in terms of
deleting characters, this won't change.
Alice wants
, so she cannot win here.
Test case
:
We have
initially.
Alice's condition is already satisfied, so
she wins immediately.
Test case
:
We have
, for which
and
.
Alice must make a move; she can delete the
last character to make
which as seen earlier satisfies Alice's
condition; so Alice wins.