Test instructions: a little boy is going up the stairs, he can walk 1 steps or 2 steps or 3 steps at a time, but some of the steps are dirty and he doesn't want to walk on the dirty steps. With a total of n steps and M dirty steps, he started on the 1th step and went to the nth step. Ask the boy if he can walk to n steps without stepping on the dirty steps.
Idea: For a given m-dirty sequence, after sorting first, there is no contiguous three numbers on the line.
1 #include<cstdio>
2 #include<cstring>
3 #include<algorithm>
4 #include<iostream>
5 #include<cstdlib>
6 #include<string>
7 #include<cmath>
8 #include<vector>
9 using namespace std;
10 const int maxn=1e5+7;
11 const double eps=1e-8;
12 const double pi=acos(-1);
13 #define ll long long
14 #define clc(a,b) memset(a,b,sizeof(a))
15
16 int main()
17 {
18 ll n;
19 int m;
20 int a[3010];
21 scanf("%I64d%d",&n,&m);
22 clc(a,0);
23 for(int i=1; i<=m; i++)
24 scanf("%d",&a[i]);
25 sort(a+1,a+1+m);
26 if(a[1]==1||a[m]==n)
27 {
28 printf("NO\n");
29 }
30 else
31 {
32 int flag=0;
33 for(int i=1; i<=m-2; i++)
34 {
35 int j=a[i];
36 if(j+1==a[i+1]&&j+2==a[i+2])
37 {
38 flag=1;
39 break;
40 }
41 }
42 if(flag)
43 printf("NO\n");
44 else
45 printf("YES\n");
46 }
47 return 0;
48 }
Codeforces 362B Petya and staircases