Related Languages
Time limit10sMemory limit512 MB
Given strings A and B and an integer k, find the longest pair of equal-length substrings, one from each string, that differ in at most k positions.
- Level
Hard8 of 10
- Topics
- Binary search, Dynamic programming, String, Two pointers
- Solved
- No attempts yet
Problem
You are studying two ancient languages, aiming to prove that they are closely related. You suspect that the words for "push-relabel flow algorithm" in both languages stem from a single ancestor. If so, they contain similar cores, i.e. subwords that do not differ much from each other.
Given two words and , determine the maximum possible , for which there are connected subwords in and in such that and have length , and differ on at most positions.
Input
The first line of input contains the number of test cases (). The descriptions of the test cases follow.
Every test case consists of three lines. The first line contains three numbers (; ). In the next two lines there are two strings and , of lengths and , respectively, each consisting of lowercase English letters.
The total length of all the words in the input does not exceed .
Output
For each test case output a single integer -- the maximum possible length of subwords that differ on at most positions.