题库练习 Binary String Sorting
← 上一题 下一题 →

A15791 | Binary String Sorting

时间限制1s
内存限制256MB
通过 / 提交0/0

题目描述

You are given a binary string $s$ consisting of only characters 0 and/or 1.

You can perform several operations on this string (possibly zero). There are two types of operations:

- choose two consecutive elements and swap them. In order to perform this operation, you pay $10^{12}$ coins;
- choose any element from the string and remove it. In order to perform this operation, you pay $10^{12}+1$ coins.

Your task is to calculate the minimum number of coins required to sort the string $s$ in non-decreasing order (i. e. transform $s$ so that $s_1 \le s_2 \le \dots \le s_m$ , where $m$ is the length of the string after applying all operations). An empty string is also considered sorted in non-decreasing order.

输入格式

The first line contains a single integer $t$ ( $1 \le t \le 10^4$ ) — the number of test cases.

The only line of each test case contains the string $s$ ( $1 \le |s| \le 3 \cdot 10^5$ ), consisting of only characters 0 and/or 1.

The sum of lengths of all given strings doesn't exceed $3 \cdot 10^5$ .

输出格式

For each test case, print a single integer — the minimum number of coins required to sort the string $s$ in non-decreasing order.

输入输出样例

输入 #1
6
100
0
0101
00101101
1001101
11111
输出 #1
1000000000001
0
1000000000000
2000000000001
2000000000002
0
C++ 编辑器
输入
输出