#P11207. 「Cfz Round 9」Rose

    ID: 11472 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>模拟递推洛谷原创O2优化洛谷比赛

「Cfz Round 9」Rose

Problem Description

You and she are playing a game.

You and she each have nn 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 TT, the number of test cases.

Then the test cases follow. For each test case:

  • The first line contains a positive integer nn.
  • The second line contains a string ss of length nn, describing her cards:
    • If sis_i is P, then her ii-th card is pink.
    • If sis_i is V, then her ii-th card is purple.
    • If sis_i is W, then her ii-th card is white.
  • The third line contains a string tt of length nn, describing your cards:
    • If tit_i is P, then your ii-th card is pink.
    • If tit_i is V, then your ii-th card is purple.
    • If tit_i is W, then your ii-th card is white.

Here, sis_i denotes the ii-th character of string ss, and similarly for tit_i.

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 00.

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 11-st test case, no operation is needed for her to win.

For the 22-nd test case, one possible plan is to change the colors of her 44-th and 55-th cards to purple.

For the 33-rd test case, one possible plan is to change the color of your 44-th card to white.

"Constraints"

For all testdata, it is guaranteed that:

  • 1T301 \le T \le 30;
  • 2n1052 \le n \le 10^5;
  • For every positive integer ii not exceeding nn, both sis_i and tit_i are characters in PVW.

This problem uses bundled tests.

  • Subtask 0 (18 points): n6n \le 6.
  • Subtask 1 (20 points): n1000n \le 1000.
  • Subtask 2 (12 points): For every positive integer ii not exceeding nn, sitis_i \ne t_i.
  • 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