#P9899. 『PG2』消除萝卜 A
『PG2』消除萝卜 A
Problem Description
There are carrots in two rows. Each carrot is either a white carrot or a red carrot. We use to represent whether the -th carrot in row is a white carrot or a red carrot.
Each time, you can pay a cost of to choose a position that currently has a carrot, and remove all carrots in the 4-connected maximal connected component consisting of carrots of the same color as that carrot. Then, for any carrot in the second row, if the corresponding position in the first row has no carrot, it will fall down to the first row.
Find the minimum total cost to remove all carrots.
Input Format
The first line contains a positive integer , the number of carrots in each row.
The second line contains integers or , where the -th one represents .
The third line contains integers or , where the -th one represents .
Output Format
Output one integer in one line, which is the answer.
3
0 1 0
1 0 1
4
6
1 0 1 0 0 1
1 1 0 1 0 1
5
10
0 0 1 1 1 1 1 1 0 0
0 1 1 0 1 0 0 0 0 1
5
10
0 1 0 1 0 1 0 1 0 1
1 0 1 0 1 0 1 0 1 0
11
10
1 0 1 1 1 0 0 1 0 1
0 0 0 1 0 1 0 1 1 0
8
Hint
For all test points, , and .
This problem uses bundled testdata.
$\sf subtask \ 1: n\leq1 \ \ \ \ \ \ \ \ \ \ \ \ \ 10pts$
$\sf subtask \ 2: n\leq10 \ \ \ \ \ \ \ \ \ \ \ 20pts$
Translated by ChatGPT 5