CF2230B.Digit String

入门

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given a string ss consisting of digits from 11 to 44.

Let's say that the string is beautiful if it is impossible to select some of its elements and write them out (in the same order as they appear in the string) to form a number that is a multiple of 44. For example, the strings 31, 222, 213 are beautiful, while the strings 143, 3123, 1322 are not. The empty string is considered beautiful.

Your task is to calculate the minimum possible number of elements in the string ss that need to be removed in order to make it beautiful.

给你一个由数字 11 到 44 组成的字符串 ss。

我们称该字符串是优美的,当且仅当无法从中选出若干字符(保持它们在原字符串中的相对顺序),拼接成一个能被 44 整除的数。例如,字符串 31、222、213 是优美的,而字符串 143、3123、1322 不是优美的。空字符串被视为优美的。

你的任务是计算:为使字符串 ss 变为优美字符串,最少需要删除多少个字符。

输入格式

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

The only line of each test case contains a string ss (1≤∣s∣≤3⋅1051 \le |s| \le 3 \cdot 10^5), consisting of digits from 11 to 44.

Additional constraint on the input: the sum of the lengths of ss over all test cases doesn't exceed 3⋅1053 \cdot 10^5.

第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4)—— 测试用例的数量。

每个测试用例仅有一行,包含一个字符串 ss(1≤∣s∣≤3⋅1051 \le |s| \le 3 \cdot 10^5),由数字 11 到 44 组成。

输入的额外约束:所有测试用例中字符串 ss 的长度总和不超过 3⋅1053 \cdot 10^5。

输出格式

For each test case, print a single integer — the minimum possible number of elements in the string ss that need to be removed in order to make it beautiful.

对于每个测试用例,输出一个整数——为使字符串 ss 变得优美,需要删除的最少元素个数。

输入输出样例

  • 输入#1

    5
    4
    13
    3244123
    24424224242
    4132423432241231

    输出#1

    1
    0
    4
    5
    9

说明/提示

In the first example, you have to delete the whole string.

In the second example, the string is already beautiful.

In the third example, you can delete the 11-st, 33-rd, 44-th, and 66-th characters, and you will get the string 213.

在第一个例子中,你需要删除整个字符串。

在第二个例子中,该字符串本身已经是优美的。

在第三个例子中,你可以删除第 11、第 33、第 44 和第 66 个字符,从而得到字符串 213。

输入解题思路,AI测评打分。不知道怎么写?

首页