#P12353. 「HCOI-R2」DataErr0r

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

「HCOI-R2」DataErr0r

Background

How do you know you are not a Program?

Problem 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 1≤l≤r≤T1\le l \le r \le T. For every ii satisfying l≤i≤rl\leq i\leq r and l≡i(mod2)l\equiv i \pmod 2, let Ti←1−TiT_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(1≤t≤104)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(1≤n≤105)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 2⋅1052\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:

  • 10101→111111\textbf 01\textbf 01\to 11111
  • 1111‾→111111\underline1\to 111

So we need 22 operations.

Constraints

This problem uses subtasks.

  • Subtask 0 (15 pts): 1≤∑N≤101\leq \sum N\leq 10.
  • Subtask 1 (35 pts): 1≤∑N≤1031\leq \sum N\leq 10^3.
  • Subtask 2 (50 pts): No additional constraints.

It is guaranteed that 1≤K≤10001\leq K\leq 1000, 1≤∑N≤1061\leq \sum N\leq 10^6, 1≤N≤1061\leq N\le 10^6.