Logo
(追記) (追記ここまで)

28189번 - LCSLCSLCS 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
10 초 1024 MB11615777.778%

문제

Suppose we have two non-empty strings $A$ and $B$ ($\lvert A \rvert, \lvert B \rvert \le 500$) of capital English letters, and two integers $n$ and $m$ such that 1ドル \le n, m \le 10^{15}$.

Let string $A^n$ be a concatenation of $n$ copies of string $A$. Let string $B^m$ be a concatenation of $m$ copies of string $B$. Your task is to find the longest common subsequence of $A^n$ and $B^m$.

입력

On the first line, there are two integers $n$ and $m$ (1ドル \le n, m \le 10^{15}$).

On the second line, there is a non-empty string $A$ with length at most 500ドル$.

On the third line, there is a non-empty string $B$ with length at most 500ドル$.

Both strings consist of capital English letters.

출력

Output one integer: the length of the longest common subsequence of $A^n$ and $B^m$.

제한

예제 입력 1

10 10
AB
BA

예제 출력 1

19

예제 입력 2

100000000 100000000
A
AB

예제 출력 2

100000000

힌트

출처

Camp > Petrozavodsk Programming Camp > Winter 2023 > Day 5: LOUD Enough Contest 2 L번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /