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

32552번 - Double Deck 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 1024 MB39292575.758%

문제

You are playing a new card game. In the game you have two decks of cards each consisting of $N \cdot K$ cards labeled with an integer from 1ドル$ to $N,ドル inclusive. Also, each type of card appears precisely $K$ times in each deck.

The rules of the game are simple. You shuffle both decks and place them face up in front of you, so at each point in time you see the top card in each deck. If the top cards are the same you can take them both and get one point. Otherwise you must discard either card. Your goal is to get as many points as possible.

You have just finished playing a round of this game and you want to know what the maximum score was, knowing the layout of both decks.

입력

The first line of the input contains two integers $N$ and $K$ (1ドル \leq N \leq 10^4, 1 \leq K \leq 15$). The second and third line of the input each contain $N \cdot K$ integers $x_i$ (1ドル \leq x_i \leq N$), describing the layout of the decks. The first number $x_1$ is the topmost card in the deck, $x_2$ is the second, and so on.

No integer in the second line and third line is repeated more than $K$ times per line.

출력

Print a single integer, the maximum possible score.

제한

예제 입력 1

3 2
3 1 2 3 1 2
2 1 3 1 3 2

예제 출력 1

4

예제 입력 2

5 3
2 3 4 5 3 5 2 2 4 3 5 1 1 1 4
5 2 3 2 3 1 4 5 1 4 5 1 4 3 2

예제 출력 2

8

힌트

출처

ICPC > Regionals > Europe > Northwestern European Regional Contest > Nordic Collegiate Programming Contest > NCPC 2024 D번

  • 문제를 만든 사람: Bergur Snorrason
(追記) (追記ここまで)

출처

대학교 대회

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

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