Whoa! how did you do that! I could never think of those nasty little optimizations!
So, let me guess, compiler works faster with smaller data types because it has to allocate smaller chunks of bytes which it finds easily in the memory, right?
Likewise, if we use arrays, compiler doesn’t have to reallocate the chunks again and again searching all over in the memory, right?
Thank you!
@sharepo Thanks for the explanation. The step 3 in your explanation intends to count the sum of beauties of all occurrences of strings from S in the suffix B[i…∣B∣−1]. I think it should be noted that your implementation additionally counts the sum of beauties of any string from S that ends in the suffix B[i…∣B∣−1] but doesn’t start in it. This works because whenever you have to use the value of suffBSum[i], you would have most definitely included the previous 25 characters before i. Thus, all strings from S that end in the suffix B[i…∣B∣−1] also need to be counted.
The setter’s solution is so simple and clear.
I have commented what I have understood. Just posting here so that it will be helpful for someone. Kindly please point out if there are any misunderstanding.
can someone please have a look at my code and point out the mistake? I computed the prefSum and SuffixSum arrays. then i am adding pref[i-25] and suff[j+25]. from (i-24) to (j+24) , i am moving along the automaton.