#P12353. 「HCOI-R2」DataErr0r

    ID: 11586 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>动态规划 DP洛谷原创O2优化洛谷月赛

「HCOI-R2」DataErr0r

Description

For two binary strings SS, TT (consisting of 00 and 11) of length nn and length n+1n+1. You can perform the following types of operations:

  1. Remove any bit from TT.

  2. Choose 1lrT1\le l \le r \le T. For every ii satisfying lirl\leq i\leq r and li(mod2)l\equiv i \pmod 2, let Ti1TiT_i\gets 1-T_i.

You need to find the minimum number of operations to make T=ST=S.

Input Format

Each test consists of multiple test cases. The first line contains a single integer t(1t104)t(1\leq t\leq 10^4) --- the number of sets of test cases. The description of test cases follows.

The first line of each test case contains a single integer n(1n105)n(1\leq n \leq 10^5) --- the length of TT.

The second line contains a single string SS with size n+1n+1.

The third line contains a single string TT with size nn.

It is guaranteed that the sum of nn does not exceed 21052\cdot 10^5.

Output Format

For each test case, output a single number, containing the answer to how many operations are needed at least to make all digits the same for SS and TT.

1
4
10101
1111
2
3
1
11
1
3
1010
010
7
10110110
0001111
1
1
2

Hint

For the first sample, we can do operations below:

  • 10101111111\textbf 01\textbf 01\to 11111
  • 1111111111\underline1\to 111

So we need 22 operations.

Constraints

This problem uses subtasks.

  • Subtask 0 (15 pts): 1N101\leq \sum N\leq 10.
  • Subtask 1 (35 pts): 1N1031\leq \sum N\leq 10^3.
  • Subtask 2 (50 pts): No additional constraints.

It is guaranteed that 1K10001\leq K\leq 1000, 1N1061\leq \sum N\leq 10^6, 1N1061\leq N\le 10^6.