B. 交换的次数

    Type: Default 1000ms 256MiB

交换的次数

You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.

Description

给定一个只由 0011 构成序列,不断扫描序列,如果发现有一个 11 与一个 00 相邻,且 11 在前,00 在后,就交换它们的位置。不断进行调整直到将所有的 00 都在序列的前一半,所有的 11 都在序列的后一半为止。

请计算需要进行多少次交换才能完成调整。

Format

Input

若干 01 字符组成的一个序列

Output

单个整数:表示交换的次数。

Samples

010101
3

Limitation

1s, 1024KiB for each test case.

nn 表示序列的长度,

30%30\% 的数据,1n201≤n≤20

60%60\% 的数据,1n50001≤n≤5000

100%100\% 的数据,1n300,0001≤n≤300,000

20241031周赛

Not Attended
Status
Done
Rule
IOI
Problem
6
Start at
2024-10-31 16:45
End at
2024-10-31 18:30
Duration
1.8 hour(s)
Host
Partic.
16