[BOJ 6042] Longest Contiguous Subsequence

View as PDF

Submit solution

Points: 2
Time limit: 1.0s
Memory limit: 128M

Problem types
Allowed languages
Assembly, Awk, C, C++, Java, Pascal, Perl, Python, Sed, Text

Bessie's friend Jessie wanted to enter a programming contest. "What are the tasks like?" she asked.</p>

Bessie, known to be knowledgeable about so many things, said "Here is a typical problem that folks solve early in their competitive career. See if you can solve it."

Perhaps you can solve it, too.

You are given two sequences of integers, S1 and S2. S1 has length L1 (1 <= L1 <= 180) and S2 has length L2 (1 <= L2 <= 180). Your job is to print out the length of the longest contiguous subsequence of numbers common to both S1 and S2. Ordered sequence S1 has elements S1_1, S1_2, ..., S1_L1 (-100 <= S1_i <= 100); S2 has elements S2_i (-100 <= S2_i <= 100).

A contiguous subsequence is a consecutive run of numbers in that sequence. The subsequences of 1 2 3 1 are: the empty sequence, "1", "1 2", "1 2 3", "1 2 3 1", "2", "2 3", "2 3 1", "3", "3 1", and a repeat occurrence of "1".

입력 형식

  • Line 1: Two space-separated integers: L1 and L2
  • Lines 2..L1+1: Line i+1 contains a single integer: S1_i
  • Lines L1+2..L1+L2+1: Line L1+i+1 contains a integer: S2_i
  • </ul>

     

    출력 형식

    • Line 1: A single integer, the length of the longest contiguous subsequence of S1 and S2
    • </ul>

       

      예제 입력

10 12
1
1
1
3
2
3
3
3
4
5
1
1
1
1
3
2
3
3
4
4
5
-8

예제 출력

7

힌트

Corresponds to the contiguous subsequence 1,1,1,3,2,3,3.</p>

 


Comments

There are no comments at the moment.