#P8301. [CoE R4 A/Stoi2041] 娘子

    ID: 9207 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 1 上传者: 标签>模拟洛谷原创O2优化枚举洛谷月赛

[CoE R4 A/Stoi2041] 娘子

Background

Problem Description

Given two 00-11 sequences aa and bb, both of length nn. First, you may choose some aia_i to flip, i.e., change 00 to 11 and 11 to 00. Then, you may permute sequence aa in any order.

After the above process, it is required that aia_i equals bib_i. Find the minimum number of flips.

Input Format

The first line contains a positive integer nn. The second line contains nn numbers representing sequence aa. The third line contains nn numbers representing sequence bb.

Output Format

Output one integer representing the answer.

3
110
101

0
5
10010
00100
1

Hint

Sample Explanation

Input #1: Reorder a=110a = 110 into a=101a = 101 to meet the requirement, so the minimum number of flips is 00.

Input #2: Flip the fourth bit of a=10010a = 10010 (counting from left to right), obtaining a=10000a = 10000, then reorder it to get a=00100a = 00100, which meets the requirement, so the minimum number of flips is 11.


Constraints

  • For 10%10\% of the testdata, n=1n = 1.
  • For another 20%20\% of the testdata, bi=0b_i = 0.
  • For another 20%20\% of the testdata, bi=1b_i = 1.
  • For 100%100\% of the testdata, 1n1031 \le n \le 10^3, ai{0,1}a_i \in \{0, 1\}, bi{0,1}b_i \in \{0, 1\}.

Translated by ChatGPT 5