Problem:


Score : 300 points

Problem Statement

There is a staircase with N steps. Takahashi is now standing at the foot of the stairs, that is, on the 0-th step.
He can climb up one or two steps at a time.

However, the treads of the a_1-th, a_2-th, a_3-th, \ldots, a_M-th steps are broken, so it is dangerous to set foot on those steps.

How many are there to climb up to the top step, that is, the N-th step, without setting foot on the broken steps?
Find the count modulo 1\ 000\ 000\ 007.

Constraints

1 \leq N \leq 10^5

0 \leq M \leq N-1

1 \leq a_1 < a_2 <  ...  < a_M \leq N-1

Input

Input is given from Standard Input in the following format:

N M
a_1
a_2
 .
 .
 .
a_M

Output

Print the number of ways to climb up the stairs under the condition, modulo 1\ 000\ 000\ 007.

Sample Input 1

6 1
3

Sample Output 1

4

There are four ways to climb up the stairs, as follows:

0 \to 1 \to 2 \to 4 \to 5 \to 6

0 \to 1 \to 2 \to 4 \to 6

0 \to 2 \to 4 \to 5 \to 6

0 \to 2 \to 4 \to 6

Sample Input 2

10 2
4
5

Sample Output 2

0

There may be no way to climb up the stairs without setting foot on the broken steps.

Sample Input 3

100 5
1
23
45
67
89

Sample Output 3

608200469

Be sure to print the count modulo 1\ 000\ 000\ 007.



Sample input:
6 1
3


Sample output:
4

Submission status: Accepted

Solution code:
N, M = map(int, input().split())

s = [0] * (N+1)

for i in range(M):
    ai = int(input())
    s[ai] = -1

s[0] = 1

if N == 1:
    print(1)
else:
    if s[1] == 0:
        s[1] = 1

    for i in range(2,N+1):
        if s[i] >= 0:
            s[i] += (max(0,s[i-1]) + max(0,s[i-2]))

    print(s[N] % 1000000007)

Submission status: Accepted

Solution code:
n, m = list(map(int, input().split()))
a = []
for i in range(m):
	a.append(int(input()))
a.sort()
f0 = 1
if len(a) > 0 and a[0] == 1:
	f1 = 0
else:
	f1 = 1
k = 0
for i in range(2, n + 1):
	while k < len(a) and a[k] < i:
		k += 1
	if k == len(a) or a[k] != i:
		f = (f0 + f1) % 1000000007
	else:
		f = 0
	f0 = f1
	f1 = f
	if f0 == f1 == 0:
		break
print(f1)

Submission status: Accepted

Solution code:
read = input 
rn = lambda :list(map(int, read().split()))
n, m  = rn()
M = []
P = 1000000007
for i in range(m):
    M.append(int(read()))
M = set(M)
dp = [0 for i in range(n + 1000)]
dp[0] = 1
for i in range(n+1):
    for nxt in range(i+1, i+3):
        if(nxt not in M):
            dp[nxt] += dp[i]
            dp[nxt] %= P
print(dp[n])

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

p = 1000000007
n,m = na()

dp = [1]*(n+1)

for i in range(m):
    a = ni()
    dp[a] = 0

for i in range(2,n+1):
    if dp[i] == 0:
        continue
    dp[i] = (dp[i-1] + dp[i-2])%p

print(dp[-1])

Submission status: Accepted

Solution code:
N, M = list(map(int, input().split()))
a = [int(input()) for i in range(M)]
a.append(-1)
dp = [0, 1]
a_flag = 0

for i in range(1, N + 1):
    if i == a[a_flag]:
        dp.append(0)
        while a[a_flag] == i:
            a_flag += 1
        continue
    dp.append(dp[i - 1] + dp[i])

print(dp[N + 1] % 1000000007)

Submission status: Accepted

Solution code:
MOD=10**9+7
N,M=map(int,input().split())
a=[-1]

for i in range(M):
  a.append(int(input()))
s=[1]
b=0 if 1 in a else 1
s.append(b)
p,q=-1,-1
j=-1
for i in range(2,N+1):
  while j<M:
    if a[j+1]<=i:
      j+=1
    else:
      break
  v=s[i-2]+s[i-1]
  if a[j]==i:
    v=0
  s.append(v%MOD)
print(s[N])

Submission status: Accepted

Solution code:
#ABC129-C
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
n,m=IL()
D=[True]*n
for i in range(m):
    D[I()-1]=False
A=[0]*n
if n==1:
    if D[0]:
        print(1)
    else:
        print(0)

else:
    if D[0]:
        A[0]=1
        if D[1]:
            A[1]=2
        else:
            A[1]=0
    else:
        A[0]=0
        if D[1]:
            A[1]=1
        else:
            A[1]=0
    for i in range(2,n):
        if D[i]:
            A[i]=A[i-1]+A[i-2]
        else:
            A[i]=0
    print(A[n-1]%1000000007)

Submission status: Accepted

Solution code:
MOD = int(1e9 + 7)

N,M = list(map(int, input().split()))
A = list()
for i in range(M):
  A.append(int(input()))

A.sort(reverse=True)

for i in range(M-1):
  if A[i+1] - A[i] == 1:
    print(0)
    exit(0)
  
dp = [0] * (N+1)
dp[0] = 1
for i in range(N):
  if len(A) > 0 and i+1 == A[-1]:
    A.pop()
  else:  
    dp[i+1] = (dp[i] + dp[i-1]) % MOD
'''
  if len(A) < 1:
    dp[i+1] = (dp[i] + dp[i-1]) % MOD
  elif i-1 < 0 or i-1 == A[-1]:
    dp[i+1] = dp[i] % MOD
  elif i == A[-1]:
    dp[i+1] = dp[i-1] % MOD
  else:
    dp[i+1] = (dp[i] + dp[i-1]) % MOD
'''
print(dp[N])
#print(dp)

Submission status: Accepted

Solution code:
N, M = map(int, input().split(" "))

X = 1000000007

flags = [True for _ in range(N+1)]
for i in range(M):
    a = int(input())
    flags[a] = False

counts = [0 for _ in range(N+1)]
counts[0] = 1

for i in range(1, N+1):
    if flags[i] == False:
        continue

    if flags[i-1] == False:
        counts[i] = counts[i-2]
    elif flags[i-2] == False:
        counts[i] = counts[i-1]
    else:
        counts[i] = (counts[i-2] + counts[i-1]) % X

print(counts[N])

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
a = [-1]+[int(input()) for _ in range(m)]+[n+1]
b = []
ans, mod = 1, 10**9+7
for i in range(m+1):
    b.append(a[i+1]-a[i]-1)

for i in range(m+1):
    diff = b[i]
    dp = [1, 1]
    if i != 0 and diff == 0:
        print(0)
        exit()
    for j in range(diff-2):
        dp.append(dp[j]+dp[j+1])
    ans *= dp[-1]
    ans %= mod
print(ans)

Submission status: Accepted

Solution code:

def dp(a):
	dp_list = [ 1 for i in range(a+1) ]
	for i in range(2,a+1):
		dp_list[i] = (dp_list[i-1] + dp_list[i-2]) % mod
	return dp_list

n, m = [ int(v) for v in input().split() ]
mod = 10**9+7
l, r = 0, 0
s = 0
stop = 0
c = -100
step_list = [ None for i in range(m+1) ]

for i in range(m):
	b = int(input())
	l, r = b-1,b+1
	d = l-s
	step_list[i] = d
	s = r
	if b == c+1:
		stop = 1
		break
	c = b
	
step_list[-1] = (n-r)


if stop == 0:
	ans = 1
	step2_list = dp(max(step_list))
	for i in step_list:
		ans = (ans*step2_list[i])%mod

	print(ans)
else:
	print(0)

Submission status: Accepted

Solution code:
# for i, a in enumerate(iterable)
# q, mod = divmod(a, b)
# divmod(i, y) returns the tuple (i//y, i%y)
# manage median(s) using two heapq https://atcoder.jp/contests/abc127/tasks/abc127_f
# visual studio code shortcut https://qiita.com/TakahiRoyte/items/cdab6fca64da386a690b
# delete line: Ctrl+Shift+k
# choose same words: Ctrl+Shift+l
import sys
from itertools import combinations, permutations # https://docs.python.org/ja/3/library/itertools.html
from math import factorial
def combinations_count(n, r):
    # faster than the following code
    # def combinations_count(n, r):
    #     return factorial(n) // (factorial(n - r) * factorial(r))
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n
    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]
    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot
    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])
    return result
def combination_with_repetition_count(n, r):
    return combinations_count(n + r - 1, r)
from collections import deque, Counter # https://docs.python.org/ja/3/library/collections.html#collections.deque
from heapq import heapify, heappop, heappush, heappushpop, heapreplace,nlargest,nsmallest # https://docs.python.org/ja/3/library/heapq.html
from copy import deepcopy, copy # https://docs.python.org/ja/3/library/copy.html
from functools import reduce
from fractions import gcd # Deprecated since version 3.5: Use math.gcd() instead.
def gcds(numbers):
    return reduce(gcd, numbers)
def lcm(i, y):
    return (i * y) // gcd(i, y)
def lcms(numbers):
    return reduce(lcm, numbers, 1)
# set the inputs
    # open(0).read() is a convenient method:
    # ei) n, m, *i = map(int, open(0).read().split())
    #     min(i[::2]) - mai(i[1::2])
    # ei2) *i, = map(int, open(0).read().split())
    #     don't forget to add comma after *i if only one variable is used
    # R = lambda: map(int, input().split()) :it's fashionable, isn't it?
    # ei1) n, k = R()
    # ei2) v = list(R())
    # ei3) bc = [list(R()) for i in range(m)]

# R = lambda: list(map(int, input().split()))
# n = int().input()
# ab = [R() for i in range(n)]
# c = R()
# c = sorted(c, reverse = True)

R = lambda: list(map(int, input().split()))
n, m = R()
a = [int(input()) for i in range(m)]

# n, m = [100, 5]
# a = [1,23,45,67,89]

dp = [-1] * (n+1)
for i in a:
    dp[i] = 0
dp[0] = 1
if dp[1] != 0:
    dp[1] = 1

for i in range(n+1):
    if dp[i] > -1:
        pass
    else:
        dp[i] = dp[i-1] + dp[i-2]

print(dp[-1] % 1000000007)

Submission status: Accepted

Solution code:

N,M = map(int,input().split())
a = []
d = {}
MOD = 10**9+7
for i in range(N+1):
    d[i] = 0
for i in range(M):
    a.append(int(input()))
    d[a[i]] = 1

dp = [0] *(N+1)

dp[0] = 1
if d[1] == 0:
    dp[1] = 1

for i in range(2,N+1):
    if d[i-1] == 1 and d[i-2] == 1:
        print(0)
        exit()

    if d[i] == 0:
        dp[i] = dp[i-1] + dp[i-2]
    else:
        dp[i] = 0

print(dp[N]%MOD)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
m = 0
if M > 0:
  broken = int(input())
else:
  broken = 0
a1, a2, a3 = 1, 0, 0
for i in range(1, N+1):
  a3, a2 = a2, a1
  if i == broken:
    a1 = 0
    m += 1
    if m < M:
      broken = int(input())
  else:
    a1 = (a2 + a3) % 1000000007
print(a1)

Submission status: Accepted

Solution code:

mod = 1000000007
n, m = list(map(int, input().split()))
dp = [0]*(n+1)
dp[0] = 1
dp[1] = 1
for _ in range(m):
    ai = int(input())
    dp[ai] = -1

for i in range(2,n+1):
    if dp[i] == -1:
        continue
    if dp[i-1] == -1:
        pre1 = 0
    else:
        pre1 = dp[i-1]
    if dp[i-2] == -1:
        pre2 = 0
    else:
        pre2 = dp[i-2]
    dp[i] = (pre1 + pre2) % mod
    
print(dp[n])

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
a = [0 for i in range(M)]
sosu = 10 ** 9 + 7
for i in range(M):
    a[i] = int(input())
seta = list(set(a))
seta.sort()
dp = [0 for i in range(N+1)]
dp[0] = 1
now = 0
for i in range(1, N+1):
    if now <= M-1 and i == seta[now]:
        now += 1
    elif i >= 2:
        dp[i] = (dp[i-2] + dp[i-1]) % sosu
    elif i == 1:
        dp[i] = dp[i-1]
#print(seta)
print(dp[N])

Submission status: Accepted

Solution code:
N, M = map(int, input().split())

a = [int(input()) for _ in range(M)]
a .append(N+10)

mod_num = 10 ** 9 + 7


def check(target, _pointer):
    while _pointer < M + 2:
        if a[_pointer] == target:
            return True, _pointer
        elif a[_pointer] < target:
            _pointer += 1
        else:
            return False, _pointer


step = [0 for _ in range(N + 1)]

step[0] = 1
step[1] = 1 if a[0] != 1 else 0

pointer = 0

for i in range(2, N + 1):
    is_broken, pointer = check(i, pointer)
    step[i] = 0 if is_broken else (step[i - 1] + step[i - 2]) % mod_num

print(step[-1])

Submission status: Accepted

Solution code:
N, M = map(int, input().split())

step_route = [-1] * (N+1)

step_route[0] = 1
step_route[1] = 1

for i in range(M):
    tmp = int(input())
    step_route[tmp] = 0

for j in range(2,N+1):  
    if step_route[j] == -1:
        step_route[j] = step_route[j-1] + step_route[j-2]
    
print(step_route[N] % 1000000007)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
a = []
stair = [1 for i in range(N+2)]
for i in range(M):
    stair[int(input())] = 0

dp = [0 for i in range(N+2)]
dp[0] = 1

MOD = 1000000007

for i in range(1, N+1):
    if stair[i] == 1:
        if i == 1:
            dp[i] = dp[i - 1] % MOD
        else:
            dp[i] = (dp[i-1] % MOD + dp[i-2] % MOD) % MOD

print(dp[N])

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
a={int(input()) for _ in range(M)}

l=[0]*(N+1)
l[0]=1

for i in range(N):
    c=l[i]%1000000007
    if i>N-2:
        if i not in a:
            l[i+1]+=c
    elif i not in a:
        l[i+1]+=c
        l[i+2]+=c

print(l[N]%1000000007)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

from collections import defaultdict

N, M = map(int, input().rstrip().split(' '))
if M == 0:
    A = [0]
else:
    A = sorted([int(input()) for _ in range(M)]) + [N + 1]
    
dp = [0] * (N+1)
dp[0] = 1
if A[0] != 1:
    dp[1] = 1
    index_A = 0
else:
    dp[1] = -1
    index_A = 1
    
for i in range(2,N+1):
    if A[index_A] == i:
        dp[i] = -1
        index_A += 1
    else:
        if dp[i-1] != -1:
            dp[i] += dp[i-1]
        if dp[i-2] != -1:
            dp[i] += dp[i-2]
            
print(dp[N] %  (1000000007))

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
A=[0]*(N+1)
for i in range(M):
  a=int(input())
  A[a]=1
mod=10**9+7
dp=[0]*(N+1)
dp[0]=1
for i in range(N):
  dp[i+1]=dp[i]
  if i>=1:
    dp[i+1]+=dp[i-1]
  if A[i+1]==1:
    dp[i+1]=0
  dp[i+1]%=mod
print(dp[N])

Submission status: Accepted

Solution code:
import sys
N,M=map(int, raw_input().split())

NG=[ 0 for i in range(N+1) ]
for i in range(M):
	a=int( sys.stdin.readline().strip() )
	NG[a]=1

dp=[ 0 for i in range(N+1) ]
dp[0]=1

mod=10**9+7

for i in range(N):
	if i+1<=N and NG[i+1]==0:
		dp[i+1]+=dp[i]
		dp[i+1]%=mod
	if  i+2<=N and NG[i+2]==0:
		dp[i+2]+=dp[i]
		dp[i+2]%=mod

print dp[N]%mod

Submission status: Accepted

Solution code:
read = input 
rn = lambda :list(map(int, read().split()))
n, m  = rn()
M = []
P = 1000000007
for i in range(m):
    M.append(int(read()))
M = set(M)
dp = [0 for i in range(n + 10)]
dp[0] = 1
for i in range(n+1):
    for nxt in range(i+1, i+3):
        if(nxt not in M):
            dp[nxt] += dp[i]
            dp[nxt] %= P
print(dp[n])

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
A = [int(input()) for _ in range(M)]
MOD = 10**9+7
table = [0]*(N+1)
table[0] = 1
broken = [1]*(N+1)
for a in A:
    broken[a] = 0

for i in range(N+1):
    if i+1<=N and broken[i+1]:
        table[i+1] += table[i]
    if i+2<=N and broken[i+2]:
        table[i+2] += table[i]

print(table[N]%MOD)

Submission status: Accepted

Solution code:
N, M = [int(s) for s in input().split()]
A = []
for _ in range(M):
    A.append(int(input()))
A = set(A)

counts = [0] * (N + 1)
for i in range(N + 1):
    if i == 0:
        counts[i] = 1
    elif i == 1:
        if i not in A:
            counts[i] = 1
    else:
        if i not in A:
            for j in [i - 2, i - 1]:
                if j not in A:
                    counts[i] += counts[j]
                    counts[i] %= 1000000007

print(counts[N])

Submission status: Accepted

Solution code:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000


N,M = map(int,input().split())
a = [0 for i in range(M)]
for i in range(M):
    a[i] = int(input())

miss_stairs = [0 for i in range(N)]
for i in range(M):
    miss_stairs[a[i]-1] = 1


dp = [0 for i in range(N+1)]
dp[0] = 1
if miss_stairs[0] == 1:
    dp[1] = 0
else:
    dp[1] = 1
for i in range(N-1):
    if miss_stairs[i+1] == 0:
        dp[i+2] = (dp[i] + dp[i+1]) % mod
# print(dp)

print(dp[-1]% mod)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
s = set()
for i in range(M):
    s.add(int(input()))
l = [0, 1]
for i in range(1, N+1):
    if i in s:
        l.append(0)
    else:
        tmp = (l[-1] + l[-2]) % 1000000007
        l.append(tmp)

ans = l[-1]
print(ans)

Submission status: Accepted

Solution code:
import sys
N,M = map(int, input().strip().split(' '))
broken = set(int(line.strip()) for line in sys.stdin) if M > 0 else set()
p = [0]*(N+2)
p[0] = 1
for i in range(N):
  # 今i段目にいる
  if i in broken:
    continue
  p[i+1] += p[i]
  p[i+2] += p[i]
print(p[N]%1000000007)

Submission status: Accepted

Solution code:
n,m = map(int, input().split())
a = [int(input()) for i in range(m)]
N = [1]+[0]*(n)
mod = 10 ** 9 + 7
out = [0] * n
for i in a:
  out[i-1] = 1
for key in range(n-1):
  now = N[key]
  if out[key] == 0:
    N[key+1] += now 
    N[key+1] %= mod
  if out[key+1] == 0:
    N[key+2] += now 
    N[key+2] %= mod
ans = (N[-1] + N[-2]) % mod
print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()

def main():
    N, M = LI()
    A = []
    for _ in range(M):
        A.append(II())
    A.append(INF)
    pre = 0
    cur = 1
    k = 0
    for i in range(1, N + 1):
        if i == A[k]:
            k += 1
            pre = cur
            cur = 0
        else:
            tmp = cur
            cur = (cur + pre) % MOD
            pre = tmp
    ans = cur
    return ans

print(main())

Submission status: Accepted

Solution code:
ll = lambda: list(map(int, input().split()))
testcases = 1
# testcases = int(input())
for testcase in range(testcases):
    [n,m]=ll()
    broken=[1]*(n+1)
    # print(broken)
    for i in range(m):
        [ai]=ll()
        broken[ai]=0
    ans=[0]*(n+1)
    ans[0]=1
    ans[1]=1*broken[1]
    for i in range(2,n+1):
        ans[i] = (ans[i-1]*broken[i-1] + ans[i-2]*broken[i-2])%(10**9+7)
    # print(ans)
    print(ans[n])

Submission status: Accepted

Solution code:
mod = 1000000007

n, m = list(map(int, input().split()))
nums = [int(input()) for _ in range(m)]
 
dp = [1] + [0 for _ in range(n)]

if len(nums) > 0 and nums[0] == 1:
	del nums[0]
else:
	dp[1] = 1
	

for i in range(2, n + 1):
	#print(i, dp, nums)
	if len(nums) ==  0:
		dp[i] = (dp[i - 1] + dp[i - 2]) % mod
	else:
		for j in range(len(nums)):
			if nums[j] > i:
				dp[i] = (dp[i - 1] + dp[i - 2]) % mod
				break
			elif nums[j] == i:
				del nums[:(j + 1)]
				break
#print(nums)
#print(dp)
print(dp[-1])

Submission status: Accepted

Solution code:
n, m = (int(i) for i in input().split())
a = [int(input()) for i in range(m)]

def Fib(n1):
    a1, b1 = 0, 1
    if n1 == 1:
        return a1
    elif n1 == 2:
        return b1
    else:
        for i in range(n1-2):
            a1, b1 = b1, a1 + b1
        return b1

l = []
pre = -1
for x in a:
    if x-pre == 1:
        print(0)
        exit()
    l.append(Fib(x-pre-1 +1))
    pre = x

l.append(Fib(n-pre +1))

res = 1
for x in l:
    res *= x

print(res % 1000000007)

Submission status: Accepted

Solution code:
MOD = 10**9 + 7
N, M = [int(x) for x in input().split()]
a = set()
for i in range(M):
    a.add(int(input()))

dp = [0]*(N + 1)
dp[0] = 1
for step in range(N):
    if not step in a:
        for width in [1, 2]:
            to = step + width
            if to <= N and not to in a:
                dp[to] = (dp[to] + dp[step]) % MOD

print(dp[N])

Submission status: Accepted

Solution code:
import os
import sys

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")

N, M = list(map(int, sys.stdin.readline().split()))
A = [int(sys.stdin.readline()) for _ in range(M)]

MOD = 10 ** 9 + 7
A = np.array(A)


# https://atcoder.jp/contests/abc066/submissions/5721975
def mod_invs(max, mod):
    """
    逆元のリスト 0 から max まで
    https://atcoder.jp/contests/abc127/submissions/5630531
    ここから。あんまり良くわかってない
    :param max:
    :param mod:
    :return:
    """
    invs = [1] * (max + 1)
    for x in range(2, max + 1):
        invs[x] = (-(mod // x) * invs[mod % x]) % mod
    return invs


def get_factorials(max, mod=None):
    """
    階乗 0!, 1!, 2!, ..., max!
    :param int max:
    :param int mod:
    :return:
    """
    ret = [1]
    n = 1
    if mod:
        for i in range(1, max + 1):
            n *= i
            n %= mod
            ret.append(n)
    else:
        for i in range(1, max + 1):
            n *= i
            ret.append(n)
    return ret


def can_go():
    # 上までいける？
    return len(A) < 2 or min(np.diff(A)) > 1


factorials = get_factorials(N, MOD)


def mod_inv(a, mod):
    """
    a の逆元
    :param int a:
    :param int mod:
    :return:
    """
    return pow(a, mod - 2, mod)


def ncr(n, r, mod=None):
    """
    scipy.misc.comb または scipy.special.comb と同じ
    組み合わせの数 nCr
    :param int n:
    :param int r:
    :param int mod: 3 以上の素数であること
    :rtype: int
    """
    if n < r:
        return 0

    # 何度も呼ぶ場合は最大の n 以下の階乗を事前に計算しておくといい
    return (
            factorials[n]
            * mod_inv(factorials[r], mod)
            * mod_inv(factorials[n - r], mod)
            % mod
    )


if not can_go():
    print(0)
    exit()


def count(n):
    ans = 0
    for r in range(n):
        if r > n - r:
            break
        ans += ncr(n - r, r, MOD)
    return max(1, ans)


step = 0
ans = 1
for a in A:
    ans = ans * count(a - step - 1) % MOD
    step = a + 1
ans *= count(N - step)
print(ans % MOD)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys

sys.setrecursionlimit(100000)
# input = sys.stdin.readline


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


class Mod:
    def __init__(self, m):
        self.m = m

    def add(self, a, b):
        return (a + b) % self.m


def slv(N, M, A):
    m = Mod(10**9 + 7)
    dp = [0] * (N+10)
    b = [False] * (N+10)
    for a in A:
        b[a] = True

    dp[0] = 1
    for i in range(N):
        if not b[i+1]:
            dp[i+1] = m.add(dp[i+1], dp[i])
        if not b[i+2]:
            dp[i+2] = m.add(dp[i+2], dp[i])
    return dp[N]


def main():
    N, M = read_int_n()
    A = [read_int() for _ in range(M)]
    print(slv(N, M, A))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n,m = map(int, input().split())
mod=10**9+7
Broken = [0]*(n+2)
for i in range(m):
    a=int(input())
    Broken[a]=1
table=[0]*(n+2)
table[0]=1
for i in range(1,n+1):
    if Broken[i]==1:
        continue
    table[i] = (table[i-1]+table[i-2]) % mod
print(table[n])

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
a = [0] * N
for _ in range(M):
    a[int(input())-1] = '!'

for i in range(N):
    if i == 0:
        if a[i] != '!':
            a[i] = 1
        else:
            a[i] = 0
    elif i == 1:
        if a[i] != '!':
            a[i] = a[i-1] + 1
        else:
            a[i] = 0
    else:
        if a[i] != '!':
            a[i] = a[i-1] + a[i-2]
        else:
            a[i] = 0

print(a[N-1] % 1000000007)

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
A=[]
for i in range(M):
    a=int(input())
    if i!=0 and a==A[-1]:
        continue
    if i!=0 and a==A[-1]+1:
        print(0)
        quit()
    A.append(a)
INF=10**9+7
B=[]
tmp=0
A.append(N+1)
for i in A:
    B.append(i-tmp)
    tmp=i+1
dp=[0]*(N+3)
dp[0]=1
dp[1]=1
dp[2]=1
for i in range(2,N+2):
    dp[i+1]=dp[i]+dp[i-1]
    dp[i+1]%=INF
ans=1
for i in B:
    ans*=dp[i]
    ans%=INF
print(ans)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
a = [int(input()) for _ in range(M)]
a.sort()
a.append(10 ** 9 + 7)
a.append(10 ** 9 + 7)

memo = [0] * (N + 1)
memo[0] = 1

idx = 0
for pos in range(1, N + 1):
    if a[idx] == pos:
        memo[pos] = 0
        for i in range(idx, N):
            if a[i] > pos: break
        idx = i
        continue
    else:
        if pos > a[idx]:
            for i in range(idx, N):
                if a[i] > pos: break
            idx = i
        #
        if pos == 1:
            memo[1] = (memo[0]) % (10 ** 9 + 7)
        else:
            memo[pos] = (memo[pos - 2] + memo[pos - 1]) % (10 ** 9 + 7)

# print("#", memo)
print(memo[-1])

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
mod=10**9+7
n,m=map(int,input().split())
A=set()
for i in range(m):
  A.add(int(input()))
S=[0]*(n+1)
S[0]=1
if 1 not in A:
  S[1]=1
for i in range(2,n+1):
  if i in A:
    S[i]=0
  else:
    S[i]=(S[i-1]+S[i-2])%mod
print(S[n]%mod)

Submission status: Accepted

Solution code:
N,M=list(map(int,input().strip().split(' ')))
B=[]
MOD=10**9+7
for _ in range(M):
    B+=[int(input())]
broken=set(B)
dp=[0]*(N+1)
dp[0]=1
for i in range(1,len(dp)):
    if i in broken:
        dp[i]=0
    else:
        if i==1:
            dp[1]=dp[0]
        else:
            dp[i]=(dp[i-1]+dp[i-2])%(MOD)
print(dp[-1])

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
a = [int(input()) for _ in range(m)]

kaidan = [True for _ in range(n+1)]
dp = [0 for _ in range(n+1)]

for i in a:
    kaidan[i] = False

dp[0] = 1
dp[1] = 1 if kaidan[1] else 0

for i in range(2,n+1):
    if kaidan[i]:
        dp[i] = (dp[i-1] + dp[i-2]) % 1000000007
    else:
        dp[i] = 0
print(dp[-1])

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
stair = [0]*(N+1)
for i in range(M):
    num = int(input())
    stair[num] = -1

stair[0] = 1
if stair[1] == -1:
    stair[1] = 0
else:
    stair[1] = 1

for j in range(2, N + 1):
    if stair[j] == -1:
        stair[j] = 0
    else:
        stair[j] = stair[j-1]+stair[j-2]

ans = stair[N] % 1000000007
print("{}".format(ans))

Submission status: Accepted

Solution code:
#!/usr/bin/env python

import sys

class bigint:
    def __init__(self,n,mod=10**9+7):
        self.n = n % mod
        self.mod = mod
        return
    #
    def __str__(self):
        return str(self.n)
    #
    def __add__(self,other):
        assert self.mod==other.mod, "modulos of the two not match"
        return bigint(self.n+other.n,self.mod)
    #
    def __iadd__(self,other):
        assert self.mod==other.mod, "modulos of the two not match"
        self.n = (self.n + other.n) % self.mod
        return self
    #
    def __sub__(self,other):
        assert self.mod==other.mod, "modulos of the two not match"
        return bigint(self.n-other.n,self.mod)
    #
    def __isub__(self,other):
        assert self.mod==other.mod, "modulos of the two not match"
        self.n = (self.n - other.n) % self.mod
        return self
#
#::::::::::::::::::::::::::::::::::::::::::::::::::
n,m = [ int(x) for x in sys.stdin.readline().split() ]
step= [bigint(0)] * (n+1)
wall= [False] * (n+1)
for i in range(m):
    am = int( sys.stdin.readline() )
    wall[am] = True
#
step[0]= bigint(1)
if not wall[1]: step[1]= bigint(1)
#
zero=bigint(0)
for i in range(2,n+1):
    if wall[i]: continue
    s1= step[i-1]
    s2= step[i-2]
    if s1==s2==zero: break
    step[i] = s1 + s2
#
print( step[n] )

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
a_list = [False]*(n+1)
for i in range(m):
    a = int(input())
    a_list[a] = True

amari = 1000000007

dp = [0]*(n+1)

dp[0] = 1
for i in range(1,n+1):
    if a_list[i]:
        dp[i] = 0
    elif i == 1:
        dp[i] = dp[0]
    else:
        dp[i] = dp[i-1]+dp[i-2]

print(dp[n]%amari)

Submission status: Accepted

Solution code:
#

import itertools
from collections import Counter
from collections import defaultdict
import bisect
from heapq import heappush, heappop

def main():
    MOD = 1000000007

    N, M = map(int, input().split())
    A = set()
    for _ in range(M):
        a = int(input())
        A.add(a)

    dp = [0] * (N + 1)
    dp[0] = 1
    for i in range(1, N + 1):
        if i not in A:
            if i == 1:
                dp[i] = dp[i - 1]
            else:
                dp[i] = dp[i - 1] + dp[i - 2]

    # print(dp)
    ans = dp[N] % MOD
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
#input=sys.stdin.readline
from collections import deque
from heapq import heappush,heappop
import re

def int_raw():
    return int(input())
 
def ss_raw():
    return input().split()
 
def ints_raw():
    return tuple(map(int, ss_raw()))


DIV = 10**9+7


def main():
    N,M = ints_raw()
    As = [int_raw() for _ in range(M)]
    is_breake = [0]*(N+1)
    for a in As:
        is_breake[a]=1
    memo = [0]*(N+1)
    memo[0]=1
    if N ==0:
        return memo[0]
    memo[1]=1 if is_breake[1]==0 else 0
    if N ==1:
        return memo[1]
    for n in range(2,N+1):
        if is_breake[n]==1:
            memo[n] =0

        else:
            memo[n]=(memo[n-2]+memo[n-1])%DIV
    return memo[N]

print(main())

Submission status: Accepted

Solution code:
#-*- coding:utf-8 -*-

N, M = map(int, input().split())
hsh = {}
for i in range(M):
    hsh[int(input())] = True

acc = [0 for _ in range(N+1)]
acc[0] = 1
if 1 in hsh:
    acc[1] = 0
else:
    acc[1] = 1

for i in range(2,N+1):
    if i-2 in hsh:  # 2段前が穴
        if i-1 in hsh: # 1段前が穴
            d = 0
        else:
            d = acc[i-1]
    else:  # 2段前が穴ではない
        if i-1 in hsh:  # 1段前が穴
            d = acc[i-2]
        else: 
            d = acc[i-1] + acc[i-2]
    acc[i] = d

# print(hsh)
# print(acc)
print(acc[-1]%1000000007)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
A = [int(input()) for i in range(M)]
INF = 10**9+7
ans = [0]*(N+1)
ans[1] = 1
if M != 0:
    s = A[0]
    if s == 1:
        ans[1] = 0
A = set(A)
ans[0] = 1

for i in range(2,N+1):
    if i in A:
        ans[i] = 0
    else:
        ans[i] = ans[i-1] + ans[i-2]
        ans[i] %= INF
        
print(ans[-1])