String Algorithm
Time limit20sMemory limit512 MB
For every k, cut s into blocks of length k, discard the tail, and count block pairs whose Hamming distance is at most one.
- Level
Hard9 of 10
- Topics
- String, Hash map, String matching, Divide and conquer
- Solved
- No attempts yet
Problem
We give you a string of length .
Fix some (). Create strings of length , the -th of them being the substring of that starts at position : .
In other words, cut the string into strings of length and discard the leftovers. Let , where is the Hamming distance. That is, is the number of pairs of strings that differ in at most one position.
Design an algorithm to compute for all from 1 to .
Input
The first line contains one positive integer (), the length of the string.
The second line contains the string of length , consisting of lowercase English characters.
Output
Print numbers, the -th of them being .