CF1809A.Garland
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You have a garland consisting of 4 colored light bulbs, the color of the i -th light bulb is si .
Initially, all the light bulbs are turned off. Your task is to turn all the light bulbs on. You can perform the following operation any number of times: select a light bulb and switch its state (turn it on if it was off, and turn it off if it was on). The only restriction on the above operation is that you can apply the operation to a light bulb only if the previous operation was applied to a light bulb of a different color (the first operation can be applied to any light bulb).
Calculate the minimum number of operations to turn all the light bulbs on, or report that this is impossible.
输入格式
The first line contains a single integer t ( 1≤t≤104 ) — the number of test cases.
The single line of each test case contains s — a sequence of 4 characters, where each character is a decimal digit. The i -th character denotes the color of the i -th light bulb.
输出格式
For each test case, print one integer — the minimum number of operations to turn all the light bulbs on. If it is impossible to turn all the bulbs on, print -1.
输入输出样例
输入#1
3 9546 0000 3313
输出#1
4 -1 6
说明/提示
In the first example, all the colors are different, so you can just turn all the bulbs on in 4 operations.
In the second example, it is impossible to turn all the bulbs on, because after you switch one light bulb, it is impossible to turn the others on.
In the third example, you can proceed as follows: turn the first light bulb on, turn the third light bulb on, turn the fourth light bulb on, turn the third light bulb off, turn the second light bulb on, turn the third light bulb on.