Codeforces Round #557 (Div. 2) [based on Forethought Future Cup - Final Round] 1162C. Hide and Seek

C. Hide and Seek

time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Alice and Bob are playing a game on a line with n cells. There are n cells labeled from 1 through n. For each i from 1 to n−1, cells i and i+1 are adjacent.

Alice initially has a token on some cell on the line, and Bob tries to guess where it is.

Bob guesses a sequence of line cell numbers x1,x2,…,xk in order. In the i-th question, Bob asks Alice if her token is currently on cell xi. That is, Alice can answer either “YES” or “NO” to each Bob’s question.

At most one time in this process, before or after answering a question, Alice is allowed to move her token from her current cell to some adjacent cell. Alice acted in such a way that she was able to answer “NO” to all of Bob’s questions.

Note that Alice can even move her token before answering the first question or after answering the last question. Alice can also choose to not move at all.

You are given n and Bob’s questions x1,…,xk. You would like to count the number of scenarios that let Alice answer “NO” to all of Bob’s questions.

Let (a,b) denote a scenario where Alice starts at cell a and ends at cell b. Two scenarios (ai,bi) and (aj,bj) are different if ai≠aj or bi≠bj.

Input

The first line contains two integers n and k (1≤n,k≤105) — the number of cells and the number of questions Bob asked.

The second line contains k integers x1,x2,…,xk (1≤xi≤n) — Bob’s questions.

Output

Print a single integer, the number of scenarios that let Alice answer “NO” to all of Bob’s questions.

Examples

input

5 3
5 1 4

outputCopy

9

input

4 8
1 2 3 4 4 3 2 1

outputCopy

0

input

100000 1
42

output

299997

Note

The notation (i,j) denotes a scenario where Alice starts at cell i and ends at cell j.

In the first example, the valid scenarios are (1,2),(2,1),(2,2),(2,3),(3,2),(3,3),(3,4),(4,3),(4,5). For example, (3,4) is valid since Alice can start at cell 3, stay there for the first three questions, then move to cell 4 after the last question.

(4,5) is valid since Alice can start at cell 4, stay there for the first question, the move to cell 5 for the next two questions. Note that (4,5) is only counted once, even though there are different questions that Alice can choose to do the move, but remember, we only count each pair of starting and ending positions once.

In the second example, Alice has no valid scenarios.

In the last example, all (i,j) where |i−j|≤1 except for (42,42) are valid scenarios.

题意:

给x个被子,将一个小球放在杯子下面,让另一个人猜,可以进行一次操作,将小球移动到所在杯子的旁的两个杯子中,或者不移动,在下面y次操作中找不到小球就行,看有几种方案。

思路:

小球不移动

y次操作中没有的操作的杯子有几个就sum加几,因为放在杯子中不动也是一种方案。

小球移动

将操作的杯子在第几次进行操作记录下来,看这个杯子两边的杯子:
1.如果是没有在操作的杯子中,不管这个杯子是不是在操作中的杯子,那么一定可以是一种方案,将小球放在没有操作被中那么一定不会发现。
2.在不是在操作中的杯子中,看杯子的操作存不存在在这个杯子操作数之前,如果存在在这个杯子操作之前,那么将操作之后的杯子放在操作过的杯子还是没问题的。

代码:

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<iomanip>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<vector>
#include<queue>
#include<set>
#include<sstream>
#define ll long long
#define mes(x,y) memset(x,y,sizeof(x))
using namespace std; 
struct node{
	ll minn,maxn;
}mm[100030];
int main(){
	std::ios::sync_with_stdio(false);
	ll x,y,i;
	while(cin>>x>>y){
		for(i=0;i<=x;i++){
			mm[i].maxn=-1;
			mm[i].minn=200000;
		}
		ll a,b=x,sum=0;
		for(i=1;i<=y;i++){
			cin>>a;
			mm[a].maxn=max(mm[a].maxn,i);
			mm[a].minn=min(mm[a].minn,i);//将操作的杯子在第几次进行操作记录下来,记录最大和最小,后面有存不存在的问题
		}
		for(i=1;i<=x;i++){
			if(mm[i].maxn==-1&&mm[i].minn==200000)sum++;//y次操作中没有的操作的杯子有几个就sum加1
			if(i!=1){
				if(mm[i].maxn<mm[i-1].minn||(mm[i-1].maxn==-1&&mm[i-1].minn==200000)){
					sum++;
				}
			}
			if(i!=x){
				if(mm[i].maxn<mm[i+1].minn||(mm[i+1].maxn==-1&&mm[i+1].minn==200000)){
					sum++;
				}
			}
		}
		/*1.如果是没有在操作的杯子中,不管这个杯子是不是在操作中的杯子,那么一定可以是一种方案,将小球放		 在没有操作被中那么一定不会发现。
        2.在不是在操作中的杯子中,看杯子的操作存不存在在这个杯子操作数之前,如果存在在这个杯子操作之前,那么将操作之后的杯子放在操作过的杯子还是没问题的。*/
		cout<<sum<<endl;
	}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

GUESSERR

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值