White Cloud has a square of n×nn×n from (1,1)(1,1) to (n,n)(n,n).
White Rabbit wants to put in several cars. Each car will start moving at the same time and move from one side of one row or one line to the other. All cars have the same speed. If two cars arrive at the same time and the same position in a grid or meet in a straight line, both cars will be damaged.
White Cloud will destroy the square mm times. In each step White Cloud will destroy one grid of the square(It will break all mm grids before cars start).Any car will break when it enters a damaged grid.
White Rabbit wants to know the maximum number of cars that can be put into to ensure that there is a way that allows all cars to perform their entire journey without damage.
(update: all cars should start at the edge of the square and go towards another side, cars which start at the corner can choose either of the two directions)
For example, in a 5×55×5 square
legal
illegal (These two cars will collide at (4,4)(4,4))
illegal (One car will go into a damaged grid)
Input
The first line of input contains two integers nn and m(n≤100000,m≤100000)m(n≤100000,m≤100000)
For the next mm lines,each line contains two integers x,y(1≤x,y≤n)x,y(1≤x,y≤n), denoting the grid which is damaged by White Cloud.
Output
Print a number,denoting the maximum number of cars White Rabbit can put into.
Example
Input
2 0
Output
4
Note
看上去极为高深复杂的一个题目,没想到本质是一个模拟
根据n的奇偶进行推测,来推出答案的公式
在算奇数的情况是,最中间的点ans会重复减掉,所以最后要++
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<set>
#include<queue>
#include<stack>
#include<map>
#include<cmath>
using namespace std;
typedef long long ll;
const int maxn = 101000;
#define inf 2147483678
int x[maxn],y[maxn];
int main()
{
int n,m;
cin>>n>>m;
int ans=0;
if(n%2)
{
ans=2*n-1;
}
else
{
ans=2*n;
}
while(m--)
{
int x1,y1;
cin>>x1>>y1;
x[x1]=1;
y[y1]=1;
}
for(int i=1;i<=n;i++)
{
if(x[i])
ans--;
if(y[i])
ans--;
}
if(n%2)
{
if(x[n/2+1]&&y[n/2+1])
{
ans++;//奇数方格中间的方格会被标记两次
}
}
//int x_m=0,y_m=0;
/*有可能有重复的行,列
while(m--)
{
int x,y;
cin>>x>>y;
ans-=2;
if(n%2)
{
if(x==(n/2+1))
x_m++;
if(y==(n/2+1))
y_m++;
}
}
if(x_m&&y_m)
ans--;
*/
cout<<ans;
return 0;
}