QOJ.ac

QOJ

حد الوقت: 1 s حد الذاكرة: 32 MB مجموع النقاط: 100

#11873. 游戏

الإحصائيات

考虑在一个 $m \times 1$ 的矩形棋盘上进行的游戏,棋盘由从 1 到 $m$ 依次编号的 $m$ 个基本方格组成。棋盘上有 $n$ 枚棋子,每枚棋子占据一个不同的方格。没有任何棋子占据编号为 $m$ 的方格。游戏中的每一步操作如下:移动方选择任意一个被占据的方格上的棋子,将其移动到编号更大的第一个未被占据的方格上。两名玩家轮流移动。将棋子移动到最后一个方格(即编号为 $m$ 的方格)的玩家获胜。

在下图中所示的情况($m = 7$)中,玩家可以将 2 号方格的棋子移动到 4 号,将 3 号方格的棋子移动到 4 号,或者将 6 号方格的棋子移动到 7 号。最后一种移动方式将结束游戏。

如果一名玩家在做出某步移动后,无论对手如何应对,他都能赢得游戏,则称该移动为获胜移动。

编写一个程序:

  • 从标准输入读取棋盘大小和棋子的初始布局,
  • 确定先手玩家在给定初始局面下可以选择的不同获胜移动的数量,
  • 将结果写入标准输出。

输入格式

输入的第一行包含两个整数 $m$ 和 $n$ ($2 \le m \le 10^9$, $1 \le n \le 10^6$, $n < m$),由单个空格分隔。第二行包含 $n$ 个递增的整数,表示棋子所在的方格编号。行内的数字由单个空格分隔。

输出格式

输出的第一行且仅包含一行,表示先手玩家在给定初始局面下可能采取的不同获胜移动的数量。

样例

输入 1

5 2
1 3

输出 1

1

输入 2

5 2
2 3

输出 2

0

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.