#P11207. 「Cfz Round 9」Rose
「Cfz Round 9」Rose
Problem Description
You and she are playing a game.
You and she each have ordered cards. The color of each card can be pink, purple, or white.
She goes first. You and she take turns, and each person must play the cards in order. The played card will be moved into the pile.
If, after someone plays a card, the numbers of cards of the three colors in the pile are the same, then that person wins and the game ends. If both you and she have finished playing all cards and no one has won, then the game is a draw.
Before the game starts, you may perform some operations. In each operation, you may change the color of any one card of either person.
You want to find the minimum number of operations needed to make her win. It can be proven that there is always at least one way to make her win.
Input Format
This problem has multiple test cases.
The first line contains a positive integer , the number of test cases.
Then the test cases follow. For each test case:
- The first line contains a positive integer .
- The second line contains a string of length , describing her cards:
- If is
P, then her -th card is pink. - If is
V, then her -th card is purple. - If is
W, then her -th card is white.
- If is
- The third line contains a string of length , describing your cards:
- If is
P, then your -th card is pink. - If is
V, then your -th card is purple. - If is
W, then your -th card is white.
- If is
Here, denotes the -th character of string , and similarly for .
Output Format
For each test case, output one integer per line: the minimum number of operations required to make her win. If she can win without any operation, output .
It can be proven that there is always at least one valid operation plan that makes her win.
3
2
PW
VP
5
PPWWP
PWVWV
6
WVPPWW
VVPVWP
0
2
1
Hint
"Sample Explanation #1"
For the -st test case, no operation is needed for her to win.
For the -nd test case, one possible plan is to change the colors of her -th and -th cards to purple.
For the -rd test case, one possible plan is to change the color of your -th card to white.
"Constraints"
For all testdata, it is guaranteed that:
- ;
- ;
- For every positive integer not exceeding , both and are characters in
PVW.
This problem uses bundled tests.
- Subtask 0 (18 points): .
- Subtask 1 (20 points): .
- Subtask 2 (12 points): For every positive integer not exceeding , .
- Subtask 3 (25 points): If you do not perform any operation, then you will not win.
- Subtask 4 (25 points): No special constraints.
Translated by ChatGPT 5