#abc320c. C - Slot Strategy 2 (Easy)
C - Slot Strategy 2 (Easy)
Score : points
问题描述
本题是问题 G 的简化版本。
存在一台拥有三个转轮的老虎机。
第 个转轮上的符号排列由字符串 表示。这里, 是一个长度为 的由数字组成的字符串。
每个转轮都有一个对应的按钮。对于每一个非负整数 ,在转轮开始旋转后恰好 秒时,高桥可以选择按下任意一个按钮或什么也不做。
如果他在转轮开始旋转后恰好 秒时按下第 个转轮对应的按钮,那么第 个转轮将会停止,并显示出 中的第 个字符。
这里, 表示 除以 后的余数。
高桥希望让所有转轮停止显示相同的字符。
找出从转轮开始旋转到所有转轮都停止所需的最小可能秒数,以实现他的目标。
如果这是不可能的,请报告这一情况。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
This problem is an easier version of Problem G.
There is a slot machine with three reels.
The arrangement of symbols on the -th reel is represented by the string . Here, is a string of length consisting of digits.
Each reel has a corresponding button. For each non-negative integer , Takahashi can either choose and press one button or do nothing exactly seconds after the reels start spinning.
If he presses the button corresponding to the -th reel exactly seconds after the reels start spinning, the -th reel will stop and display the -th character of .
Here, denotes the remainder when is divided by .
Takahashi wants to stop all the reels so that all the displayed characters are the same.
Find the minimum possible number of seconds from the start of the spin until all the reels are stopped so that his goal is achieved.
If this is impossible, report that fact.
Constraints
- is an integer.
- is a string of length consisting of digits.
Input
The input is given from Standard Input in the following format:
Output
If it is impossible to stop all the reels so that all the displayed characters are the same, print -1
.
Otherwise, print the minimum possible number of seconds from the start of the spin until such a state is achieved.
Sample Input 1
10
1937458062
8124690357
2385760149
Sample Output 1
6
Takahashi can stop each reel as follows so that seconds after the reels start spinning, all the reels display 8
.
- Press the button corresponding to the second reel seconds after the reels start spinning. The second reel stops and displays
8
, the -st character of . - Press the button corresponding to the third reel seconds after the reels start spinning. The third reel stops and displays
8
, the -rd character of . - Press the button corresponding to the first reel seconds after the reels start spinning. The first reel stops and displays
8
, the -th character of .
There is no way to make the reels display the same character in or fewer seconds, so print .
Sample Input 2
20
01234567890123456789
01234567890123456789
01234567890123456789
Sample Output 2
20
Note that he must stop all the reels and make them display the same character.
Sample Input 3
5
11111
22222
33333
Sample Output 3
-1
It is impossible to stop the reels so that all the displayed characters are the same.
In this case, print -1
.
update @ 2024/3/10 01:38:30