포럼
문제 ICPC00301

D. Double Deck

설명

Image taken from wikimedia.org. 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
출력
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
출력
8
문제 정보

생성자가 기록되지 않았습니다.

출처 ICPC NCPC 2024

평가 및 의견

D. Double Deck

개요
출제자 난이도 Unrated 레이팅 미적용 의견 0 / 1 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

D. Double Deck

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8