QOJ.ac

QOJ

時間限制: 1 s 記憶體限制: 1024 MB 總分: 100 可 Hack ✓

#18582. 滾動吧,骰子!

统计

fill2714 以擅長骰子遊戲而聞名。 但事實上,他擅長骰子遊戲的原因是他可以操控骰子,使其擲出想要的數字。

骰子遊戲的規則如下:

  • 遊戲盤由無限多個格子排成一列,從起點 $0$ 號格開始,依序標記為非負整數。
  • 遊戲盤上有 $K$ 個無人島格子,第 $i$ 個無人島格子位於 $x_i$ 號格。
  • 所有玩家將棋子放在 $0$ 號格。
  • 輪到玩家的回合時,該玩家執行以下步驟:
    1. 擲兩顆標有 $1$ 到 $N$ 的骰子,並將棋子向前移動兩顆骰子點數之和的距離。
    2. 若步驟 1 中擲出的兩顆骰子點數相同,則執行雙倍 (Double) 行動。
    3. 若不符合步驟 2 的條件,則結束回合。
    4. 在回合結束前,重複執行步驟 1、2、3。
  • 雙倍行動如下:
    1. 若這是第 $M$ 次雙倍行動,則移動至 $0$ 號格並結束回合。
    2. 若不符合步驟 1 的條件,且目前所在的格子是無人島,則結束回合。
    3. 若不符合步驟 1、2 的條件,則繼續進行回合。

fill2714 這次決定再次操控骰子,以便在第一回合中移動到盡可能遠的格子。 請計算 fill2714 在第一回合結束時,最多能移動到第幾號格。

輸入格式

第一行包含三個由空格分隔的整數:骰子點數最大值 $N$、雙倍次數限制 $M$ 以及無人島格子的數量 $K$。 $(1 \le N \le 10^{12}; 1 \le M \le 10^5; 0 \le K \le 10^5)$

第二行包含 $x_{1}, x_{2}, \ldots, x_{K}$,由空格分隔。 $(1 \le x_{i} \le 10^{18}; x_{i} < x_{i+1})$

輸出格式

第一行輸出 fill2714 在第一回合結束時,最多能移動到第幾號格。

範例

範例輸入 1

6 3 10
1 2 6 8 10 12 22 26 28 30

範例輸出 1

27

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.