luogu#P8001. Easy Strings Merging

Easy Strings Merging

Problem Description

You are given nn binary strings. Each time, you may remove one character from the beginning of some string and append it to the end of a new string SS. Maximize the number of adjacent pairs of equal characters in SS.

Input Format

The first line contains a positive integer nn, representing the number of strings.

The next nn lines each contain a binary string.

Output Format

Output one integer in a single line, representing the answer.

3
0011
0110
1100
9

Hint

Sample Explanation

In an optimal strategy, the indices of the chosen strings at each step are 1,1,2,1,2,3,1,2,3,2,3,31,1,2,1,2,3,1,2,3,2,3,3, and the final S=000111111000S=000111111000.

Constraints

This problem uses bundled testdata.

Let ss be the sum of lengths of the input binary strings.

Subtask ID Score Special Constraints
00 55 n=1n=1
11 2020 n2n\le 2, s10s\le 10
22 2525 n5n\le 5, s30s\le 30
33 n100n\le 100, s200s\le 200
44 No special constraints

For all testdata, it is guaranteed that 1ns1061\le n\le s\le 10^6.

Translated by ChatGPT 5