QOJ.ac

QOJ

시간 제한: 1 s 메모리 제한: 128 MB 총점: 100

#23818. 好玩嘅卡牌遊戲

통계

題目描述

有好多張卡牌,每張卡牌上面都寫住一個由 $1$ 到 $1000$ 嘅整數。安娜(Anna)同埋布魯諾(Bruno)用呢啲卡牌玩下面嘅遊戲。

安娜有一疊由 $A$ 張卡牌組成嘅牌堆,布魯諾有一疊由 $B$ 張卡牌組成嘅牌堆。安娜由佢嘅 $A$ 張卡牌入面丟棄任意數量嘅卡牌(亦可以係 $0$ 張)嚟組成一個新嘅牌堆。布魯諾由佢嗰疊由 $B$ 張卡牌組成嘅牌堆頂部丟棄若干張卡牌(亦可以係 $0$ 張),同埋由底部丟棄若干張卡牌(亦可以係 $0$ 張)嚟組成一個新嘅牌堆。不過,喺丟棄卡牌嗰陣,唔會改變剩低卡牌嘅順序。如果用呢種方式整出嚟嘅 $2$ 個牌堆一致,咁其中一個牌堆入面包含嘅卡牌張數就會成為呢 $2$ 位玩家嘅得分。喺度,話 $2$ 個牌堆一致,係指每個牌堆包含嘅卡牌張數 $n$ 相同,而且對於由上至下嘅第 $i$ 張卡牌($1 \le i \le n$),卡牌上面寫住嘅整數全部都一樣。

例如,假設安娜有一疊 $5$ 張卡牌嘅牌堆,由上至下依次序寫住整數 $1, 2, 3, 4, 5$;布魯諾有一疊 $4$ 張卡牌嘅牌堆,由上至下依次序寫住整數 $3, 1, 4, 1$。呢個時候,如果安娜丟棄卡牌 $2, 3, 5$,而布魯諾丟棄最上面嘅卡牌 $3$ 同埋最下面嘅卡牌 $1$,咁呢 $2$ 位玩家嘅牌堆就會一致。呢個時候,因為剩低嘅其中一個牌堆入面包含嘅卡牌張數係 $2$,所以呢 $2$ 位玩家會得到 $2$ 分。

Figure

我哋想搵出呢 $2$ 位玩家得分嘅最大值。

任務

給定安娜同埋布魯諾所持有嘅卡牌牌堆嘅資訊,請編寫一個程式,求出呢 $2$ 位玩家得分嘅最大值。

限制

  • $1 \le A \le 5000$:安娜牌堆入面嘅卡牌張數。
  • $1 \le B \le 5000$:布魯諾牌堆入面嘅卡牌張數。
  • 卡牌上面寫住嘅整數喺 $1$ 到 $1000$ 之間(包括首尾)。

輸入格式

從標準輸入讀取以下數據。

  • 第 $1$ 行寫有用空格隔開嘅整數 $A, B$。
  • 第 $2$ 行寫有用空格隔開嘅 $A$ 個整數;第 $i$ 個整數($1 \le i \le A$)表示安娜嘅牌堆入面由上至下第 $i$ 張卡牌上面寫住嘅整數。
  • 第 $3$ 行寫有用空格隔開嘅 $B$ 個整數;第 $j$ 個整數($1 \le j \le B$)表示布魯諾嘅牌堆入面由上至下第 $j$ 張卡牌上面寫住嘅整數。

輸出格式

向標準輸出輸出 $1$ 行,表示呢 $2$ 位玩家得分嘅最大值嘅整數。

子任務

  • 喺佔總分 $10\%$ 嘅評測數據入面,滿足 $A \le 10, B \le 10$。
  • 喺佔總分 $50\%$ 嘅評測數據入面,滿足 $A \le 100, B \le 100$。

樣例 1

輸入

5 4
1 2 3 4 5
3 1 4 1

輸出

2

呢個樣例對應題目描述入面嘅例子。

樣例 2

輸入

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

輸出

3

喺呢個樣例入面,呢 $2$ 位玩家有 $2$ 種方法可以得到 $3$ 分。

  • 當安娜丟棄卡牌 $1, 2, 3$,而布魯諾丟棄卡牌 $2, 3$ 嗰陣,呢 $2$ 位玩家嘅牌堆由上至下都會變成 $4, 5, 4$,呢 $2$ 位玩家嘅得分係 $3$ 分。
  • 另外,當安娜丟棄卡牌 $1, 5, 4$,而布魯諾丟棄頂部嘅卡牌 $4$ 同埋 $5$ 嗰陣,呢 $2$ 位玩家嘅牌堆由上至下都會變成 $4, 2, 3$,呢 $2$ 位玩家嘅得分係 $3$ 分。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.