#P7389. 「EZEC-6」游戏
「EZEC-6」游戏
Description
Alice and Bob play a game.
Alice initially has stones, and Bob initially has stones. They play for several rounds. In round , the loser gives the winner stones. The game stops when, in some round, the loser does not have enough stones.
Given , find the maximum number of rounds the game can be played (not including the ending round), and construct a win-loss sequence containing only A and B such that the length of the sequence equals your answer, and at any time the number of stones each person has is non-negative.
Input Format
This problem has multiple test cases.
The first line contains a positive integer , representing the number of test cases.
For each test case:
One line contains non-negative integers .
Output Format
For each test case:
The first line contains an integer, representing the maximum number of rounds the game can be played. Let your answer be .
The second line contains a string of length , representing the win-loss sequence.
If Alice wins round , then the -th character of your sequence is A. If Bob wins round , then the -th character is B.
3
1 1
0 3
1 3
2
BA
3
AAB
3
ABA
Hint
This problem uses bundled tests.
- Subtask 1 (6 points): .
- Subtask 2 (8 points): .
- Subtask 3 (8 points): .
- Subtask 4 (8 points): .
- Subtask 5 (25 points): .
- Subtask 6 (45 points): No special constraints.
For of the testdata, , , , .
If you correctly answer the maximum number of rounds, but your constructed win-loss sequence is invalid, you will get of the score for that test point (rounded down).
Note that if you cannot construct a win-loss sequence, you still need to output a non-empty string.
The output size of this problem is large, so please use a fast output method.
Translated by ChatGPT 5
京公网安备 11011102002149号