| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 10 초 | 16 MB (하단 참고) | 25 | 8 | 8 | 38.095% |
Note that the memory limit is unusually low.
Let $\operatorname{LCS}(A, B)$ denote the length of the longest common subsequence of integer sequences $A = \langle a_1, a_2, \ldots, a_n \rangle$ and $B = \langle b_1, b_2, \ldots, b_m \rangle$.
For an integer $x$, let $A + x$ denote the sequence $\langle a_1 + x, a_2 + x, \ldots, a_n + x \rangle$.
You are given two integer sequences $A$ and $B$. Find the sum of $\operatorname{LCS}(A + x, B)$ over all integers $x$ from $-10^{100}$ to $10^{100}$.
The first line contains two integers $n$ and $m$ ($1 \le n, m \le 4000$).
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-10^8 \le a_i \le 10^8$).
The third line contains $m$ integers $b_1, b_2, \ldots, b_m$ ($-10^8 \le b_i \le 10^8$).
Print the sum of $\operatorname{LCS}(A + x, B)$ over all integers $x$ from $-10^{100}$ to $10^{100}$.
3 4 5 5 8 3 6 3 6
6
An integer sequence $P$ is a subsequence of an integer sequence $Q$ if $P$ can be obtained from $Q$ by deletion of several (possibly zero or all) elements. The longest common subsequence of sequences $A$ and $B$ is the longest sequence $C$ that is a subsequence of both $A$ and $B$.
In the example test:
Therefore the answer is $1 + 3 + 2 = 6$.
Camp > Petrozavodsk Programming Camp > Winter 2022 > Day 7: ICPC Camp Day 2, Gennady Korotkevich Contest 6 G번
Contest > Open Cup > 2021/2022 Season > Stage 13: Grand Prix of Gomel G번
C++17, Java 8, C11, C99, C++98, C++11, C++14, Java 8 (OpenJDK), Java 11, C++20, Kotlin (JVM), Java 15, C99 (Clang), C++98 (Clang), C++11 (Clang), C++14 (Clang), C11 (Clang), C++17 (Clang), C++20 (Clang), C90, C2x, C90 (Clang), C2x (Clang)