#P10164. [DTCPC 2024] 戈布

[DTCPC 2024] 戈布

Problem Description

For a 0101 sequence {an}\{a_n\}, find the minimum kk such that there exists a set {(lk,rk)}\{(l_k,r_k)\} that satisfies the following condition.

  • i[1,n]\forall i\in[1,n], ai=1a_i=1 if and only if j[1,k]\exist j\in[1,k], i[lj,rj]i\in[l_j,r_j].

It can be proven that the set {(lk,rk)}\{(l_k,r_k)\} that satisfies the condition is unique.

A 0101 sequence {an}\{a_n\} is good if and only if i[1,k)\forall i\in[1,k), rili<ri+1li+1r_i-l_i<r_{i+1}-l_{i+1}.

In simple terms, a 0101 sequence is good if and only if the lengths of the maximal consecutive segments of 11 formed from left to right are strictly increasing.

Given the sequence {an}\{a_n\}, you may perform the following operation any number of times (or do nothing):

  • Choose i,j(ij)i,j(i\ne j) and swap ai,aja_i,a_j.

Find the minimum number of operations needed to make {an}\{a_n\} a good sequence.

Input Format

One line containing a 0101 sequence {an}\{a_n\} of length nn (n800n\leq 800).

Output Format

One line containing one number, which is the answer.

01101
1
01011
0

Hint

Translated by ChatGPT 5