CF333B.Chips

普及+/提高

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Gerald plays the following game. He has a checkered field of size n × n cells, where m various cells are banned. Before the game, he has to put a few chips on some border (but not corner) board cells. Then for n - 1 minutes, Gerald every minute moves each chip into an adjacent cell. He moves each chip from its original edge to the opposite edge. Gerald loses in this game in each of the three cases:

  • At least one of the chips at least once fell to the banned cell.
  • At least once two chips were on the same cell.
  • At least once two chips swapped in a minute (for example, if you stand two chips on two opposite border cells of a row with even length, this situation happens in the middle of the row).

In that case he loses and earns 0 points. When nothing like that happened, he wins and earns the number of points equal to the number of chips he managed to put on the board. Help Gerald earn the most points.

杰拉尔德玩如下游戏:他有一个大小为 n×nn \times n 的方格棋盘,其中 mm 个不同的格子被禁止使用。游戏开始前,他必须在棋盘的某些边界(但非角)格子上放置若干棋子。随后,在接下来的 n−1n-1 分钟内,杰拉尔德每分钟将每个棋子移动到一个相邻的格子中,且每个棋子均需从其初始所在的边界边移动至对边。若在游戏过程中出现以下三种情况中的任意一种,杰拉尔德即告失败,并得分为 0:

  • 至少有一个棋子曾落入某个被禁止的格子;
  • 至少有一次,两个或更多棋子位于同一格子;
  • 至少有一次,两个棋子在一分钟内彼此交换了位置(例如,若将两个棋子分别放在某一行两端的边界格子上,且该行长度为偶数,则它们将在该行正中间发生交换)。

若全程未发生上述任一情况,则杰拉尔德获胜,其得分为他成功放置在棋盘上的棋子总数。请帮助杰拉尔德获得尽可能高的分数。

输入格式

The first line contains two space-separated integers n and m (2 ≤ n ≤ 1000, 0 ≤ m ≤ 105) — the size of the field and the number of banned cells. Next m lines each contain two space-separated integers. Specifically, the i-th of these lines contains numbers x__i and y__i (1 ≤ x__i, y__i ≤ n) — the coordinates of the i-th banned cell. All given cells are distinct.

Consider the field rows numbered from top to bottom from 1 to n, and the columns — from left to right from 1 to n.

第一行包含两个以空格分隔的整数 nn 和 mm(2≤n≤10002 \leq n \leq 1000,0≤m≤1050 \leq m \leq 10^5)—— 分别表示棋盘的大小以及被禁止的格子数量。接下来的 mm 行每行包含两个以空格分隔的整数;具体而言,第 ii 行包含数字 xix_i 和 yiy_i(1≤xi,yi≤n1 \leq x_i, y_i \leq n)—— 表示第 ii 个被禁止的格子的坐标。所有给定的格子互不相同。

将棋盘的行从上到下编号为 11 到 nn,列从左到右编号为 11 到 nn。

输出格式

Print a single integer — the maximum points Gerald can earn in this game.

输出一个整数——Gerald 在该游戏中能获得的最高分数。

输入输出样例

  • 输入#1

    3 1
    2 2

    输出#1

    0
  • 输入#2

    3 0

    输出#2

    1
  • 输入#3

    4 3
    3 1
    3 2
    3 3

    输出#3

    1

说明/提示

In the first test the answer equals zero as we can't put chips into the corner cells.

In the second sample we can place one chip into either cell (1, 2), or cell (3, 2), or cell (2, 1), or cell (2, 3). We cannot place two chips.

In the third sample we can only place one chip into either cell (2, 1), or cell (2, 4).

在第一个测试用例中,答案为零,因为我们无法将棋子放入角落的格子中。

在第二个样例中,我们可以将一个棋子放入格子 (1,2)(1, 2)、(3,2)(3, 2)、(2,1)(2, 1) 或 (2,3)(2, 3) 中的任意一个。我们无法放置两个棋子。

在第三个样例中,我们只能将一个棋子放入格子 (2,1)(2, 1) 或 (2,4)(2, 4) 中的任意一个。

输入解题思路,AI测评打分。不知道怎么写?

首页