String array
Time limit2sMemory limit512 MB
Count strings S of length 1 to W such that the repeated periodic filling of X matches the given patch F at the fixed offset.
- Level
Hard8 of 10
- Topics
- String matching, Number theory, Math
- Solved
- No attempts yet
Problem
Yeongseon wants to fill an array X with letters. X has 10,000 rows and W columns.
Before filling it she picks one string S whose length is at least 1 and at most W. S consists of lowercase letters only.
The filling algorithm is the following.
cur = 0
for (int i=0; i<10000; i++) {
for (int j=0; j<W; j++) {
X[i][j] = S[cur];
cur = (cur + 1) % S.length();
}
}
You are given a patch F with N rows and M columns. The top left cell of F sits in row and column of X, so holds for every and . Write a program that counts the strings S for which the array X built by the algorithm above matches F at that position.
Input
The first line contains the number of rows N of F, the number of columns M of F, the number of columns W of X, and the row index and column index where the top left cell of F sits. (, , , )
Each of the next N lines contains one row of F, written as M lowercase letters.
Output
Print the number of strings S that satisfy the condition, modulo 1,000,000,009.