#abc307h. Ex - Marquee
Ex - Marquee
Score : points
问题描述
存在一个长度为 的字符串 ,由大写和小写英文字母组成,该字符串显示在一个宽度为 的电子公告板上。字符串 从右向左以每步一个字符的宽度滚动。
显示重复一个包含 个状态的循环,在字符串 的最后一个字符从左边消失时,字符串 的第一个字符从右边边缘出现。
例如,当 且 ABC 时,公告板按顺序循环显示以下七个状态:
ABC..BC...C........A...AB..ABC.ABC.
(. 表示没有字符显示的位置。)
更精确地说,在 时,有不相同的显示状态,其中:
- 让 表示 除以 的余数。公告板左侧第 个位置显示的是:若 ,则显示 的第 个字符;否则不显示任何内容。
给你一个长度为 的字符串 ,它由大写英文字母、小写英文字母、. 和 _ 组成。
找出在公告板的 个状态中,除去 _ 位置外与 相匹配的状态数目。
更精确地说,计算满足以下条件的状态数量。
- 对于 ,满足以下任一条件:
- 字符串 的第 个字符是
_。 - 公告板左侧第 个位置显示的字符等于字符串 的第 个字符。
- 公告板左侧第 个位置没有显示任何内容,并且字符串 的第 个字符是
.。
- 字符串 的第 个字符是
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
There is a length string consisting of uppercase and lowercase English letters displayed on an electronic bulletin board with a width of . The string scrolls from right to left by a width of one character at a time.
The display repeats a cycle of states, with the first character of appearing from the right edge when the last character of disappears from the left edge.
For example, when and ABC, the board displays the following seven states in a loop:
ABC..BC...C........A...AB..ABC.ABC.
(. represents a position where no character is displayed.)
More precisely, there are distinct states for in which the display is as follows.
- Let be the remainder when is divided by . The -th position from the left of the board displays the -th character of when , and nothing otherwise.
You are given a length string consisting of uppercase English letters, lowercase English letters, ., and _.
Find the number of states among the states of the board that coincide except for the positions with _.
More precisely, find the number of states that satisfy the following condition.
- For every , one of the following holds.
- The -th character of is
_. - The character displayed at the -th position from the left of the board is equal to the -th character of .
- Nothing is displayed at the -th position from the left of the board, and the -th character of is
..
- The -th character of is
Constraints
- and are integers.
- is a string of length consisting of uppercase and lowercase English letters.
- is a string of length consisting of uppercase and lowercase English letters,
., and_.
Input
The input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
3 5
ABC
..___
Sample Output 1
3
There are three desired states, where the board displays ....A, ...AB, ..ABC.
Sample Input 2
11 15
abracadabra
__.._________ab
Sample Output 2
2
Sample Input 3
20 30
abaababbbabaabababba
__a____b_____a________________
Sample Output 3
2
Sample Input 4
1 1
a
_
Sample Output 4
1
update @ 2024/3/10 08:43:09