|시간 제한||메모리 제한||제출||정답||맞은 사람||정답 비율|
|2 초||512 MB||1||1||1||100.000%|
A string hashing function is an algorithm that turns arbitrary strings into numbers. If S is a string of length N, one simple hashing function is
S * 31^(N‐1) + S * 31^(N‐2) + ... + S[N‐1]
where S[i] is the ASCII code of the i'th character and ^ indicates exponentiation. The computation is done using big integer arithmetic (it never overflows).
Note: In most programming languages ^ does NOT perform exponentiation.
Here are some example strings and the corresponding values computed by this hashing function:
Sometimes different strings have the same hash (like the second and third strings above).
A string is considered valid if all its characters have ASCII codes in the range 32 to 126 inclusive.
Your task is to count the number of valid strings that have the same hash as a given input string.
Input consists of several lines. Each line describes a string using a sequence of space‐separated integers in the
N S S ... S[N‐1]
N is the length of the string (1 <= N <= 1000) and S[i] is the ASCII code of the i'th character (32 <= S[i] <= 126).
A value of N = 0 indicates the end of the input and should not be processed.
For each test case, print a single integer: the number of valid strings that have the same hash as the input string (including the input string itself), modulo 1,000,000,007 (10^9 + 7).
2 97 98 3 72 105 33 3 32 32 32 0
3 12 1
The first line in the input describes the string "ab" which hashes to 3105. There are two other valid strings with the same hash: "bC" (ASCII: 98 67) and "c$" (ASCII: 99 36), so in total there are three strings. The string which in ASCII is 100 5 also hashes to 3105 but is not valid because 5 is outside the range 32 to 126.
The second line corresponds to the string "Hi!" which hashes to 72480. There are 12 valid strings with this hash.
The third line corresponds to a string with three spaces which hashes to 31776. There are no other valid strings that hash to 31776.