LCSLCSLCS
시간 제한10초메모리 제한1024 MB
문자열 A를 n번, B를 m번 이어 붙인 두 문자열의 최장 공통 부분 수열 길이를 구한다. n과 m은 10^15까지 커질 수 있다.
문제
Suppose we have two non-empty strings and () of capital English letters, and two integers and such that .
Let string be a concatenation of copies of string . Let string be a concatenation of copies of string . Your task is to find the longest common subsequence of and .
입력
On the first line, there are two integers and ().
On the second line, there is a non-empty string with length at most .
On the third line, there is a non-empty string with length at most .
Both strings consist of capital English letters.
출력
Output one integer: the length of the longest common subsequence of and .