#P8153. 「PMOI-5」送分题/Yet Another Easy Strings Merging

「PMOI-5」送分题/Yet Another Easy Strings Merging

Background

This problem is collecting fake solutions and hack testdata. If you got AC with a fake solution, feel free to private message the setter with a hack.

The information may be redundant.

— command_block, "Pre-exam Tips"

djy was reading P8001, misread the problem, got very upset, and then this problem was created.

Problem Description

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

For example, if you have two strings 1010 111, and you remove the first character of the first string, then 010 is appended to SS.

Strings can be reused.

Input Format

The first line contains a positive integer nn, indicating 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.

1
1100
4
5
10010
10000
01110
111111
000000
48 

Hint

[Sample Explanation]

By removing the first character each time, the changes of SS are 100->10000->100000, and the answer is 44.

[Constraints]

Let s|s| be the length of string ss, and sis_i be the ii-th string.
This problem uses bundled tests.

  • Subtask 1 (30 pts): n,si11n,\sum|s_i|\le 11.
  • Subtask 2 (30 pts): n,si103n,\sum|s_i|\le 10^3.
  • Subtask 3 (30 pts): n,si105n,\sum|s_i|\le 10^5.
  • Subtask 4 (10 pts): no additional constraints.

For 100%100\% of the data, 1n1061\le n\le 10^6, nsi106n\le \sum |s_i|\le 10^6, and for all i[1,n]i\in [1,n], si1|s_i|\ge 1.

Translated by ChatGPT 5