Minimum Index

TimeLimit:1500MS  MemoryLimit:524288KB
64-bit integer IO format:%I64d
未提交 | 登录后收藏
Problem Description
Let s=$s_1$ $s_2$$ \cdots $$s_n$ be a string of length n. For any integer k between 1 to n, the $k^{th}$ suffix of s is defined as $s_k$ $s_{k+1}$$ \cdots $$s_n$. For example, the $4^{th}$ suffix of “contest” is “test” and the $1^{st}$ suffix of “suffix” is “suffix” itself.

One can consider lexicographically smallest suffix of s. Let the $k^{th}$ suffix is lexicographically minimum among all suffixes of s. Conveniently, let’s call such k minimum index of s. Given a string t=$t_1$ $t_2 \cdots t_n$, your task is to calculate the sum of (minimum index of $t_1$ $t_2 \cdots t_i$)$ \cdot 1112^{i-1}$ over all i=1,2,3,$ \cdots $,n. This value may be too large, you are only required to print it modulo $10^9$+7.
Input
The first line of the input contains a single integer T (1≤T≤10 000), the number of test cases. Each of the next T lines contains a non-empty string with at most $10^6$ lowercase English letters. The total length of the input string over all test cases doesn’t exceed $2 \cdot 10^7$.
Output
For each test case, you should print the answer in a single line.
SampleInput
1
aab
SampleOutput
1238769

 Hint The minimum index of “a”, “aa”, “aab” is 1, 2, 1 respectively. So the answer is (1+2∙1112+1112^2) mod (10^9+7)=1238769.
Submit
题目统计信息详细
总AC数0
通过人数0
尝试人数0
总提交量0
AC率0.00%
AC该题后可以添加标签
贴完标签可以获得20ACB。
并且可以获得本题所有提交代码查看权限。
点击标题可以显示标签。
如果你还没认真思考过这题,请不要查看标签
如果您已经通过了该题,请务为该题贴上标签

T^T Online Judge

[BUG反馈] [FAQ] [闽ICP备17026590号-1]
当前版本:3.24 系统时间: