Defining substring
For a string P with characters P1, P2,…, Pq, let us denote by P[i, j] the substring Pi, Pi+1,…, Pj.
Defining longest common prefix
LCP(S1, S2,…, SK), is defined as largest possible integer j such that S1[1, j] = S2[1, j] = … = SK[1, j].
You are given an array of N strings, A1, A2 ,…, AN and an integer K. Count how many indices (i, j) exist such that 1 ≤ i ≤ j ≤ N and LCP(Ai, Ai+1,…, Aj) ≥ K. Print required answer modulo 109+7.
Note that K does not exceed the length of any of the N strings. K <= min(len(Ai)) for all i
, Pi+1,…, Pj.Defining longest common prefix
LCP(S1, S2,…, Sk), is defined as largest possible integer j such that S1[1, j] = S2[1, j] = … = Sk[1, j].
You are given an array of N strings, A1, A2 ,…, AN and an integer K. Count how many indices (i, j) exist such that 1 ≤ i ≤ j ≤ N and LCP(Ai, Ai+1,…, Aj) ≥ K. Print required answer modulo 109+7.
Note that K does not exceed the length of any of the N strings. K <= min(len(Ai)) for all i
For example,
A = ["ab", "ac", "bc"] and K=1.
LCP(A[1, 1]) = LCP(A[2, 2]) = LCP(A[3, 3]) = 2 LCP(A[1, 2]) = LCP("ab", "ac") = 1 LCP(A[1, 3]) = LCP("ab", "ac", "bc") = 0 LCP(A[2, 3]) = LCP("ac", "bc") = 0So, the answer is 4. Return your answer % MOD = 1000000007
Constraints
1 ≤ Sum of length of all strings ≤ 5*105. Strings consist of small alphabets only.
Defining substring
For a string P with characters P1, P2,…, Pq, let us denote by P[i, j] the substring Pi, Pi+1,…, Pj.
Defining longest common prefix
LCP(S1, S2,…, SK), is defined as largest possible integer j such that S1[1, j] = S2[1, j] = … = SK[1, j].
You are given an array of N strings, A1, A2 ,…, AN and an integer K. Count how many indices (i, j) exist such that 1 ≤ i ≤ j ≤ N and LCP(Ai, Ai+1,…, Aj) ≥ K. Print required answer modulo 109+7.
Note that K does not exceed the length of any of the N strings. K <= min(len(Ai)) for all i
For example,
A = ["ab", "ac", "bc"] and K=1.
LCP(A[1, 1]) = LCP(A[2, 2]) = LCP(A[3, 3]) = 2 LCP(A[1, 2]) = LCP("ab", "ac") = 1 LCP(A[1, 3]) = LCP("ab", "ac", "bc") = 0 LCP(A[2, 3]) = LCP("ac", "bc") = 0So, the answer is 4. Return your answer % MOD = 1000000007
Constraints
1 ≤ Sum of length of all strings ≤ 5*105. Strings consist of small alphabets only.
Defining substring
For a string P with characters P1, P2,…, Pq, let us denote by P[i, j] the substring Pi, Pi+1,…, Pj.
Defining longest common prefix
LCP(S1, S2,…, Sk), is defined as largest possible integer j such that S1[1, j] = S2[1, j] = … = Sk[1, j].
You are given an array of N strings, A1, A2 ,…, AN and an integer K. Count how many indices (i, j) exist such that 1 ≤ i ≤ j ≤ N and LCP(Ai, Ai+1,…, Aj) ≥ K. Print required answer modulo 109+7.
Note that K does not exceed the length of any of the N strings. K <= min(len(Ai)) for all i
For example,
A = ["ab", "ac", "bc"] and K=1.
LCP(A[1, 1]) = LCP(A[2, 2]) = LCP(A[3, 3]) = 2 LCP(A[1, 2]) = LCP("ab", "ac") = 1 LCP(A[1, 3]) = LCP("ab", "ac", "bc") = 0 LCP(A[2, 3]) = LCP("ac", "bc") = 0So, the answer is 4. Return your answer % MOD = 1000000007
Constraints
1 ≤ Sum of length of all strings ≤ 5*105. Strings consist of small alphabets only.
I have been trying to solve a modification of the Longest Common PrefixLongest Common Prefix problem. It is defined below.
Defining substring
Defining substring
For a string P with characters P1P1, P2 P2,…, PqPq, let us denote by P[i, j] the substring PiPi, Pi+1,…, Pj.
Defining longest common prefix
LCP(S1, S2,…, SK), is defined as largest possible integer j such that S1[1, j] = S2[1, j] = … = SK[1, j].
You are given an array of N strings, A1, A2 ,…, AN and an integer K. Count how many indices (i, j) exist such that 1 ≤ i ≤ j ≤ N and LCP(Ai, Ai+1,…, Aj) ≥ K. Print required answer modulo 109+7.
Note that K does not exceed the length of any of the N strings. K <= min(len(Ai)) for all i
For example, Pi+1
A = ["ab",… "ac", Pj"bc"] and K=1.
Defining longest common prefix
LCP(A[1, 1]) = LCP(A[2, 2]) = LCP(A[3, 3]) = 2 LCP(A[1, 2]) = LCP("ab", "ac") = 1 LCP(A[1, 3]) = LCP("ab", "ac", "bc") = 0 LCP(A[2, 3]) = LCP("ac", "bc") = 0LCP(S1, S2 ,…, SK)So, the answer is defined as largest possible integer j such that S1[1, j] = S2[1, j] = … = SK[1, j]4. Return your answer % MOD = 1000000007
You are given an array of N strings, A1, A2 ,…, AN and an integer K. Count how many indices (i, j) exist such that 1 ≤ i ≤ j ≤ N and LCP(Ai, Ai+1 ,…, Aj) ≥ K. Print required answer modulo 10^9+7.
Note that K does not exceed the length of any of the N strings. K <= min(len(A_i)) for all i
For example,
A = ["ab", "ac", "bc"] and K=1.
LCP(A[1, 1]) = LCP(A[2, 2]) = LCP(A[3, 3]) = 2 LCP(A[1, 2]) = LCP("ab", "ac") = 1 LCP(A[1, 3]) = LCP("ab", "ac", "bc") = 0 LCP(A[2, 3]) = LCP("ac", "bc") = 0 So, the answer is 4. Return your answer % MOD = 1000000007
Constraints
Constraints
1 ≤ Sum of length of all strings ≤ 5*10^55*105. Strings consist of small alphabets alphabets only.
I have been trying to solve a modification of the Longest Common Prefix problem. It is defined below.
Defining substring
For a string P with characters P1, P2 ,…, Pq, let us denote by P[i, j] the substring Pi, Pi+1 ,…, Pj.
Defining longest common prefix
LCP(S1, S2 ,…, SK), is defined as largest possible integer j such that S1[1, j] = S2[1, j] = … = SK[1, j].
You are given an array of N strings, A1, A2 ,…, AN and an integer K. Count how many indices (i, j) exist such that 1 ≤ i ≤ j ≤ N and LCP(Ai, Ai+1 ,…, Aj) ≥ K. Print required answer modulo 10^9+7.
Note that K does not exceed the length of any of the N strings. K <= min(len(A_i)) for all i
For example,
A = ["ab", "ac", "bc"] and K=1.
LCP(A[1, 1]) = LCP(A[2, 2]) = LCP(A[3, 3]) = 2 LCP(A[1, 2]) = LCP("ab", "ac") = 1 LCP(A[1, 3]) = LCP("ab", "ac", "bc") = 0 LCP(A[2, 3]) = LCP("ac", "bc") = 0 So, the answer is 4. Return your answer % MOD = 1000000007
Constraints
1 ≤ Sum of length of all strings ≤ 5*10^5. Strings consist of small alphabets only.
I have been trying to solve a modification of the Longest Common Prefix problem. It is defined below.
Defining substring
For a string P with characters P1, P2,…, Pq, let us denote by P[i, j] the substring Pi, Pi+1,…, Pj.
Defining longest common prefix
LCP(S1, S2,…, SK), is defined as largest possible integer j such that S1[1, j] = S2[1, j] = … = SK[1, j].
You are given an array of N strings, A1, A2 ,…, AN and an integer K. Count how many indices (i, j) exist such that 1 ≤ i ≤ j ≤ N and LCP(Ai, Ai+1,…, Aj) ≥ K. Print required answer modulo 109+7.
Note that K does not exceed the length of any of the N strings. K <= min(len(Ai)) for all i
For example,
A = ["ab", "ac", "bc"] and K=1.
LCP(A[1, 1]) = LCP(A[2, 2]) = LCP(A[3, 3]) = 2 LCP(A[1, 2]) = LCP("ab", "ac") = 1 LCP(A[1, 3]) = LCP("ab", "ac", "bc") = 0 LCP(A[2, 3]) = LCP("ac", "bc") = 0So, the answer is 4. Return your answer % MOD = 1000000007
Constraints
1 ≤ Sum of length of all strings ≤ 5*105. Strings consist of small alphabets only.
The online judge (InterviewBit) does not accept this solution in terms of time complexity. Can anyone think of a way to improve it? Any help will be appreciated!
The online judge (InterviewBit) does not accept this solution in terms of time complexity. Can anyone think of a way to improve it? Any help will be appreciated!
The online judge (InterviewBit) does not accept this solution in terms of time complexity. Can anyone think of a way to improve it?