There is a binary string
. Alice and Bob are playing a game on it.
Each turn, the following happens:
- Alice selects a subsequence in and removes it from . (a subsequence is a length subsequence whose first character is and second character is )
- Bob selects a subsequence in and removes it from .
- After both players have moved, the turn is called completed and Alice scores point. Then, the next turn begins.
If either player is unable to move (there isn't any subsequence left in ), that turn ends immediately and the game ends.
Alice tries to maximize her points, while Bob tries to minimize Alice's points. Find how many points Alice would score if both players play optimally.
Input Format
- The first line contains a single integer — the number of test cases.
- Each of the next lines contains a binary string .
Output Format
For each test case, output on a new line a single integer — Alice's score when both players play optimally.
Constraints
- The sum of across all tests doesn't exceed
Subtasks
- Subtask 1 (25 Points):
- The sum of across all tests doesn't exceed
- Subtask 2 (25 Points):
- The sum of across all tests doesn't exceed
- Subtask 3 (50 Points):
- No further constraints.
Sample Input 1
4
01010101
0101
10
01001011
Sample Output 1
1
1
0
2
Explanation
In the first example, this is one of the possible outcomes.
Turn :
- Alice removes subsequence from , so becomes
010101
. - Bob removes subsequence from , so becomes
0110
. - Alice scores one point and the first turn ends.
Turn 2:
- Alice removes subsequence from , so becomes
10
. - Bob has nothing to do, so the game ends immediately.
Thus, Alice has one point in total.
No comments:
Post a Comment