QOJ.ac

QOJ

시간 제한: 2 s 메모리 제한: 1024 MB 총점: 100 해킹 가능 ✓

#16893. 冒險卡牌遊戲

통계

全球知名遊戲公司 KDH Corp. 開發的「回合制冒險卡牌遊戲」——《隨便用卡牌打怪獸》終於在今天上市了!以下是遊戲規則說明:

  • 玩家在遊戲開始時,手牌中持有編號從 $1$ 到 $K$ 的卡牌各一張。
  • 遊戲總共包含 $N$ 個回合,每個回合中最多會出現一隻編號從 $1$ 到 $K$ 的怪物。
  • 玩家在每個回合中最多可以打出兩張手牌。也可以選擇不打出任何卡牌直接結束該回合。
  • 若在怪物出現的回合中,玩家打出了與該怪物編號相同的卡牌,即可用該卡牌擊敗怪物。
  • 若在某個回合出現的怪物未能在該回合內被擊敗,該怪物會在回合結束後逃跑。
  • 當玩家將手牌全部用盡後,在回合結束時,會重新獲得編號從 $1$ 到 $K$ 的卡牌各一張。
  • 擊敗的怪物越多,獲得的分數就越高。

民間遊戲高手道勳在《隨便用卡牌打怪獸》上市後立刻奪得第一名,但他的勁敵強民正威脅著他的榜首地位!焦急的道勳想要先記錄下可能達到的最高分數,以防止第一名被搶走。為了讓道勳能更穩固地保住第一名,請幫他計算在每場遊戲中最多可以擊敗的怪物數量。

輸入格式

第一行包含遊戲的總回合數 $N$ 以及卡牌與怪物的種類數 $K$,兩者以空格分隔。($1 \le N, K \le 500\,000$)

第二行包含各回合出現的怪物種類 $c_1, c_2, \dots, c_N$,以空格分隔。($0 \le c_i \le K$) 若 $c_i = 0$,則表示第 $i$ 回合沒有怪物出現。

輸出格式

輸出可以擊敗的怪物數量之最大值。

範例

輸入 1

6 4
1 1 2 2 3 3

輸出 1

5

輸入 2

10 5
1 2 2 0 3 3 0 5 4 4

輸出 2

7

說明

在第一個範例中,若在各回合依序打出卡牌,可以擊敗除第 2 回合出現的 1 號怪物以外的所有怪物:

i. 打出 1 號卡牌與 3 號卡牌,擊敗 1 號怪物。 ii. 打出 4 號卡牌。1 號怪物未被擊敗而逃跑。 iii. 打出 2 號卡牌,擊敗 2 號怪物。 因為四張卡牌皆已打出,回合結束後重新獲得所有卡牌。 iv. 打出 1 號卡牌與 2 號卡牌,擊敗 2 號怪物。 v. 打出 3 號卡牌與 4 號卡牌,擊敗 3 號怪物。 因為四張卡牌皆已打出,回合結束後重新獲得所有卡牌。 vi. 打出 3 號卡牌,擊敗 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.