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:
# coding: utf-8
import sys
input = sys.stdin.readline
N,M=map(int,input().split())
A=[0]*M
dp=[-1]*(N+1)
for i in range(M):
    tmp=int(input())
    dp[tmp]=0
#print(dp)
dp[0]=1
dp[1]=0 if dp[1]==0 else 1

for i in range(2,N+1):
    if dp[i]!=0:
        dp[i]=dp[i-1]+dp[i-2]
        
print(dp[N]%(10**9+7))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

mod = 10**9+7
n, m = map(int, input().split())
l = [int(input()) for _ in range(m)]

t2 = 0
t1 = 1

for i in range(1,n+1):
  if l == [] or i != l[0]:
    t0 = (t2+t1)%mod
  else:
    l.pop(0)
    t0 = 0
  t2 = t1
  t1 = t0

print(t0)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

mod = 10**9+7
n, m = map(int, input().split())
l = [0]*n
for _ in range(m):
  l[int(input())-1] = 1

t, s = 1, 0

for i in range(n):
  if l[i]:
    t, s = 0, t
  else:
    t, s = (s+t)%mod, t

print(t)

Submission status: Accepted

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

s = 0
t = 1

for i in range(n):
  if l[i] > 0:
    t, s = 0, t
  else:
    t, s = (s+t)%mod, t

print(t)

Submission status: Accepted

Solution code:
mod = 10**9+7
n, m = map(int, input().split())
l = [int(input()) for _ in range(m)]

t2 = 0
t1 = 1

for i in range(1,n+1):
  if l == [] or i != l[0]:
    t0 = (t2+t1)%mod
  else:
    l.pop(0)
    t0 = 0
  t2 = t1
  t1 = t0

print(t0)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
DP = [1 for i in range(N+1)]
MOD = 10**9 + 7

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

for i in range(2,N+1):
    
    if (DP[i] != 0):
        DP[i] = DP[i-1] + DP[i-2]
print(DP[N]%MOD)

Submission status: Accepted

Solution code:
### 動的計画法
#ABC129C - Typical Stairs
#https://atcoder.jp/contests/abc129/tasks/abc129_c

mod = 10**9+7
n, m = list(map(int,input().split()))
a = [int(input()) for _ in range(m)]
dp = [float("Inf")]*(n+1)
for i in range(m):
    dp[a[i]] = 0
dp[0] = 1
if dp[1] == float("Inf"):
    dp[1] = 1
for i in range(2,n+1):
    if dp[i] == float("Inf"):
        dp[i] = dp[i-1] + dp[i-2]
print(dp[n]%mod)

Submission status: Accepted

Solution code:
MOD = 1e9 + 7

N, M = [int(i) for i in input().split()]
issafe = [True] * (N + 1)
for i in range(M):
    a = int(input())
    # a 段目は壊れている
    issafe[a] = False

# dp
dp = [0] * (N + 1)
# 初期化
dp[0] = 1
if issafe[1]:
    dp[1] = 1

for i in range(2, N + 1):
    # i - 1 段目が安全なら
    if issafe[i - 1]:
        dp[i] += dp[i - 1]
    # i - 2 段目が安全なら
    if issafe[i - 2]:
        dp[i] += dp[i - 2]
    dp[i] %= MOD
print(int(dp[N]))

Submission status: Accepted

Solution code:
import sys
inputs = sys.stdin.readlines()

n, m = map(int, inputs[0].split())
B = set(map(int, inputs[1:]))
A = [0 if i in B else 1 for i in range(n+3)]
MOD = 10 ** 9 + 7

dp = [0]*(n+1)
dp[0], dp[1] = 1, A[1]
for i in range(1, n):
    dp[i+1] = (dp[i] + dp[i-1]) * A[i+1] % MOD
    if A[i] + A[i+1] == 0:
        break
print(dp[n])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import _collections
import string
from functools import lru_cache

class cin():
    def int():
        return int(sys.stdin.readline().rstrip())
    def string():
        return sys.stdin.readline().rstrip()
    def mapInt():
        return [int(x) for x in cin.string().split()]
    def stringList(n):
        return [input() for i in range(n)]
    def intListList(n):
        return [cin.mapInt() for i in range(n)]
    def intColsList(n):
        return [int(input()) for i in range(n)]
        
class Math():
    def gcd(a,b):
        if b == 0:
            return a
        return Math.gcd(b,a % b)
    def roundUp(a,b):
        return -(-a // b)
    def toUpperMultiple(a,x):
        return Math.roundUp(a,x) * x
    def toLowerMultiple(a,x):
        return (a // x) * x
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

MOD = int(1e09) + 7

def main():
    N ,M = cin.mapInt()
    A = [True] * (N + 1)
    for i in range(M):
        a = cin.int()
        A[a - 1] = False

    dp = [0] * (N + 1)
    dp[0] = 1
    for i in range(N):
        if A[i] == True:
            dp[i + 1] = dp[i] + dp[i - 1]
            dp[i + 1] %= MOD
    print(dp[N])
    return

if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

#print(dp)
print(dp[-1]%1000000007)

Submission status: Accepted

Solution code:
def main():
    mod = 1000000007
    N, M, *A = map(int, open(0).read().split())
    A = set(A)
    F = [0] * (N + 1)
    F[0] = 1
    if 1 not in A:
        F[1] = 1
    for i in range(2, N + 1):
        if i not in A:
            F[i] = (F[i-1] + F[i-2]) % mod
    print(F[N])


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

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 I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n,m=LI()
  l=[True for _ in range(n+1)]
  for _ in range(m):
    l[I()]=False

  dp=[0 for _ in range(n+1)]
  dp[0]=1
  for i in range(n):
    for j in range(1,3):
      if i+j<=n and l[i]:
        dp[i+j]+=dp[i]

  # print(dp)
  return dp[n]%mod

# main()
print(main())

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
aset = set([int(input()) for _ in range(M)])
dp = [0] * (N + 1)
dp[0] = 1
for i in range(N):
    for j in range(i + 1, min(N, i + 2) + 1):
        if j not in aset:
            dp[j] += dp[i]
            dp[j] %= 10**9 + 7
print(dp[N])

Submission status: Accepted

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

cnt = 0
dp_table = [0 for i in range(n + 10)]
dp_table[0] = 1
dp_table[1] = 1

for i in range(m):
    dp_table[a[i]] = -10 ** 9 + 7

for i in range(2, n + 10):
    if dp_table[i] > -1:
        dp_table[i] = (max(dp_table[i - 1], 0) + max(dp_table[i - 2], 0)) % (10 ** 9 + 7)

print(dp_table[n])

Submission status: Accepted

Solution code:
n, m = list(map(int, input().split()))

stairs =[1, 1] + [0] * (n - 1)

for _ in range(m):
  stairs[int(input())] = "broken"
  
for i in range(2, n + 1):
  if stairs[i] != "broken":
    if stairs[i - 2] != "broken":
      stairs[i] += stairs[i - 2]
    if stairs[i - 1] != "broken":
      stairs[i] += stairs[i - 1]

print(stairs[-1] % 1000000007)

Submission status: Accepted

Solution code:
import numpy as np
n, m = map(int, input().split())
stairs = set([int(input()) for i in range(m)])
ans = [1] * (n+1)
mod = 10**9 + 7
if 1 in stairs:
    ans[1] -= 1
for i in range(2, n+1):
    if i in stairs:
        ans[i] = 0
    else:
        ans[i] = ans[i-1] + ans[i-2]

print(ans[-1]%mod)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
a = set([int(input())for i in range(m)])
dp = [0]*(n+1)
dp[0] = 1
if 1 in a :
    dp[1] = 0
else:
    dp[1] = 1
for i in range(2,n+1):
    if i in a:
        continue
    dp[i] = (dp[i-1]+dp[i-2])%1000000007
print(dp[n])

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
hole_ids = {int(input()) - 1: 0 for _ in range(m)}
X = 1000000007


def solve(n, hole_ids):
    nums = []
    # nums = [0] * n
    for i in range(n):
        if i in hole_ids:
            nums.append(0)
            # nums[i] = 0
            continue

        if i == 0:
            nums.append(1)
            # nums[i] = 1
        elif i == 1:
            # 1つ前から1段上がるから2つ前から2個飛ばし
            nums.append(nums[-1] + 1)
            # nums[i] = nums[i-1] + 1
        else:
            nums.append((nums[-1] % X + nums[-2] % X) % X)
            # nums[i] = (nums[i-1] + nums[i-2]) % X
    return nums[-1]


print(solve(n, hole_ids))

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
hole_ids = {int(input()) - 1: 0 for _ in range(m)}
X = 1000000007


def solve(n, hole_ids):
    # nums = []
    nums = [0] * n
    for i in range(n):
        if i in hole_ids:
            # nums.append(0)
            nums[i] = 0
            continue

        if i == 0:
            # nums.append(1)
            nums[i] = 1
        elif i == 1:
            # 1つ前から1段上がるから2つ前から2個飛ばし
            # nums.append(nums[-1] + 1)
            nums[i] = nums[i-1] + 1
        else:
            # nums.append((nums[-1] % X + nums[-2] % X) % X)
            nums[i] = (nums[i-1] + nums[i-2]) % X
    return nums[-1]


print(solve(n, hole_ids))

Submission status: Accepted

Solution code:
#python3

MOD = int(1e9+7)

def main():
    n, m = map(int, input().split())
    a = [int(input()) for _ in range(m)]
    broken = [0]*(n+1)
    for i in a:
        broken[i] = 1; 

    dp = [0]*(n+2)
    dp[n] = 1
    for i in reversed(range(n)):
        if broken[i]:
            dp[i] = 0;
            continue; 
        dp[i] = (dp[i+1] + dp[i+2]) % MOD

    print(dp[0])
main()

Submission status: Accepted

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

mod = int(1e9+7)

dp = [0]*N

if N == 1:
    print(1)
    exit()

if a[0] and a[1]:
    dp[0] = 1
    dp[1] = 2
elif not a[0] and a[1]:
    dp[1] = 1

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

print(dp[N-1]%mod)

Submission status: Accepted

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

dp = [0] * (n + 1)
dp[0] = 1

ls.append(0)

if ls[0] == 1:
	dp[1] = 0
	del ls[0]
else:
	dp[1] = 1

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

print(dp[n] % 1000000007)

Submission status: Accepted

Solution code:
MOD = 1e9 + 7

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

dp = [0] * (n+1)
dp[0] = 1
for i in range(1, n+1):
    if a[i]:
        continue
    if i > 1:
        dp[i] = (dp[i-1] + dp[i-2]) % MOD
    else:
        dp[i] = dp[i-1]

print(int(dp[n]))

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
a = []
for i in range(m):
  a.append(int(input()))
# 0: 1, 1: 1, 2: 2(1+1, 2), 3: 3(1+1+1, 1+2, 2+1)
# dp[i] = dp[i-1] + dp[i-2]
dp = [0]*(n+1)
dp[0] = 1
for i in range(m):
  dp[a[i]] = -1
for i in range(n):
  if dp[i] == -1:
    continue
  if dp[i+1] != -1:
    dp[i+1] += dp[i]
    dp[i+1] %= 10**9+7
  if i+2 != n+1:
    if dp[i+2] != -1:
      dp[i+2] += dp[i]
      dp[i+2] %= 10**9+7
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

dp = [0] * (n+1)
flag = [False] * (n+1)
for i in a:
    flag[i] = True

dp[0] = 1
if 1 not in a:
    dp[1] = 1

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

print(dp[-1])

Submission status: Accepted

Solution code:
def main():
    n,m = map(int,input().split())
    a = [-1]
    d = 10**9+7
    for i in range(m):
        a.append(int(input()))
    a.append(n+1)
    fib = [1,1]
    for i in range(n):
        fib.append(fib[-2]+fib[-1])
    ans = 1
    for i in range(m+1):
        x = a[i+1]-a[i]-2
        if x == -1:
            ans = 0
            break
        ans = ans*fib[x]%d
    print(ans)
    
if __name__ == '__main__':
    main()

Submission status: Accepted

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

MOD = 10 ** 9 + 7

S = [0] * (N + 1)
S[0] = 1
for a in A:
  S[a] = -1

for i in range(N):
  if S[i] != -1:
    if i + 1 < N + 1 and S[i + 1] != -1:
      S[i + 1] = (S[i + 1] + S[i]) % MOD
    if i + 2 < N + 1 and S[i + 2] != -1:
      S[i + 2] = (S[i + 2] + S[i]) % MOD
      
print(S[N])

Submission status: Accepted

Solution code:
import sys
from collections import deque
 
def main():
    N, M = map(int, input().split())
    a = deque([int(sys.stdin.readline().strip()) for _ in range(M)])
 
    atmp = -1
    if len(a) != 0:
        atmp = a.popleft()
 
    dp=[0] * (N+1)
    for i in range(0, N+1):
        if i == atmp:
            if len(a) != 0:
                atmp = a.popleft()
            continue
 
        if i == 0 or i == 1:
            dp[i] = 1
            continue
 
        if dp[i-1] == 0 and dp[i-2] == 0:
            break
 
 
        dp[i] = dp[i-1] + dp[i-2]
 
    print(dp[N] % 1000000007)
 
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
dp = [0]*(10**6)

N,M = map(int, input().split())
A = {}
for i in range(N+1):
    A[i] = 0
for _ in range(M):
    a = int(input())
    A[a] = 1

dp[0] = 1

for i in range(1,N+1,1):

    if A[i]==1:
        continue
    if i==1:
        dp[i] += dp[i-1]
        continue
    if A[i-1]==0:
        dp[i] += dp[i-1]
    if A[i-2]==0:
        dp[i] += dp[i-2]


print(dp[N]%(10**9+7))

Submission status: Accepted

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

fib=[1]*(N+1)
for i in range(2,N+1):
    fib[i]=fib[i-1]+fib[i-2]
fib.append(0)

ans=fib[a[0]-1]
for i in range(M):
    ans*=fib[a[i+1]-a[i]-2]
    ans%=mod
print(ans%mod)

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    MOD = 1000000007
    n, m = map(int, input().split())
    a = {int(input()) for _ in range(m)}

    dp = [0] * (n+1)
    dp[:2] = 1, 1 if 1 not in a else 0

    for i in range(2, n+1):
        if i not in a:
            dp[i] += (dp[i-1] + dp[i-2]) % MOD
    print(dp[-1])

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
DP = [0] * (N+1)
F = [True] * (N+1)
ANS = -1

BC=-1
for i in range(M):
  f = int(input())
  if BC == f - 1:
    print(0)
    exit(0)
  BC = f
  F[f] = False

DP[0] = 1
if F[1]:
  DP[1] = 1
for i in range(2, N+1):
  if F[i - 1]:
    DP[i] += DP[i-1]
  if F[i-2]:
    DP[i] += DP[i-2]
A = 1000000007
#print(DP)
#print(F)
print(DP[N] % A)

Submission status: Accepted

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

dp = [1 for _ in range(N + 1)]
for i in range(1, N+1):
    if A[i] == True:
        if i - 2 >= 0:
            dp[i] = (dp[i-1] + dp[i-2]) % MOD
        else:
            dp[i] = (dp[i - 1]) % MOD
    else:
        dp[i] = 0
print(dp[-1] % MOD)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())

safe = [True] * (n + 1)
for _ in range(m):
  safe[int(input())] = False
dp = [0] * (n + 1)

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

for i in range(2, n + 1):
  if safe[i - 1]:
    dp[i] += dp[i - 1]
  if safe[i - 2]:
    dp[i] += dp[i - 2]
  dp[i] %= 1000000007
 
print(dp.pop())

Submission status: Accepted

Solution code:
n,m=map(int, input().split())

oks = [True]*(n+1)
for _ in range(m):
    broken = int(input())
    oks[broken] = False

dp = [0]*(n+2)
dp[1] = 1

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


mod = 10**9+7
print(dp[n+1]%mod)

Submission status: Accepted

Solution code:
# DP
mod = 10 ** 9 + 7
N, M = map(int, input().split())
A = [int(input()) for _ in range(M)]

if N == 1:
    print(1)
    exit()
if N == 2:
    if M == 0:
        print(2)
    if M == 1:
        print(1)
    exit()

safe = [True] * (N+1)
for i in range(M):
    safe[A[i]] = False 

dp = [0] * (N+1)
dp[0] = 0
dp[1] = 1
dp[2] = 2

if 1 in A:
    dp[1] = 0
    dp[2] = 1
if 2 in A:
    dp[2] = 0

for i in range(3, N+1):
    if safe[i]:
        dp[i] = dp[i-1] + dp[i-2]

##print(dp)
print((dp[N]+mod)%mod)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 5 + 10)
mod = 10 ** 9 + 7

# フィボナッチ数列
fib_memo = {}
def fib(N):
    if N < 2: return 1
    if N not in fib_memo:
        fib_memo[N] = fib(N-1) + fib(N-2)
    return fib_memo[N]

N, M = map(int, input().split())
A = [int(input()) for _ in range(M)]

tmp_list = [0] * (M+1)
now_kaidan = 0
for i in range(M):
    tmp_list[i] = (A[i] - 1) - now_kaidan
    now_kaidan = A[i] + 1
tmp_list[-1] = N-now_kaidan
ans = 1

for v in tmp_list:
    if v == -1:     # 壊れた階段が連続している時は0移動方法がない
        print(0)
        exit()
    ans *= fib(v)
    ans %= mod

print(ans%mod)

Submission status: Accepted

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

memo[0] = 1
if 1 in a:
    memo[1] = 0
else:
    memo[1] = 1
for i in range(2,n+1):
    if i in a:
        continue
    memo[i] = (memo[i-1] + memo[i-2])%1000000007

print(memo[n])

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
brokensteps = set([int(input()) for x in range(m)])
dp = [0] * (n+1)
for i in range(n+1):
    if i in brokensteps:
        dp[i] = 0
        continue
    
    elif i <= 1:
        dp[i] = 1

    else:
        dp[i] = (dp[i-1] + dp[i-2])%(10**9+7)

print(dp[n])

Submission status: Accepted

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

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

dp = [0 for i in range(N+1)]
dp[0] = 1
if bs[1] != False: dp[1] = 1

for i in range(2,N+1):
    if bs[i-1] != False:
        dp[i] += dp[i - 1]
    if bs[i - 2] != False:
        dp[i] += dp[i - 2]

print(dp[N] % 1000000007)

Submission status: Accepted

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

r = [0]*(n+1)
r[0] = 1
if 1 in a:
  r[1] = 0
else:
  r[1] = 1
for i in range(2, n+1):
  if i in a:
    continue
  r[i] = (r[i-1] + r[i-2])%1000000007

print(r[n])

Submission status: Accepted

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

up = [0]*(m+1)
if m == 0:
  up[0] = n
else:
  up[0] = a[0]-1
  up[m] = n - a[m-1]-1
  for i in range(m-1):
    up[i+1] = a[i+1]-a[i]-2

ans = 1
if -1 in up:
  ans = 0
else:
  f = [0]*(max(up)+1)
  f[0] = 1
  if max(up) > 0:
    f[1] = 1
    for i in range(2, max(up)+1):
      f[i] = f[i-1] + f[i-2]
  for i in range(m+1):
    ans *= f[up[i]]

print(ans % 1000000007)

Submission status: Accepted

Solution code:
import sys
from collections import deque

def main():
    N, M = map(int, input().split())
    a = deque([int(sys.stdin.readline().strip()) for _ in range(M)])

    atmp = -1
    if len(a) != 0:
        atmp = a.popleft()

    dp=[0] * (N+1)
    for i in range(0, N+1):
        if i == atmp:
            if len(a) != 0:
                atmp = a.popleft()
            continue

        if i == 0 or i == 1:
            dp[i] = 1
            continue

        if dp[i-1] == 0 and dp[i-2] == 0:
            break


        dp[i] = dp[i-1] + dp[i-2]

    print(dp[N] % 1000000007)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    MOD = 1000000007
    n, m = map(int, input().split())
    a = set([int(input()) for _ in range(m)])

    dp = [0] * (n+1)
    dp[:2] = 1, 1 if 1 not in a else 0

    for i in range(2, n+1):
        if i not in a:
            dp[i] += (dp[i-1] + dp[i-2]) % MOD
    print(dp[-1])

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()

def pl(n):
    if n > 0:
        return n
    else:
        return 0

def main():
    MOD = 1000000007
    n, m = map(int, input().split())

    dp = [0] * (n+1)
    dp[0] = 1
    
    for _ in range(m):
        dp[int(input())] = -1

    for i in range(1, n+1):
        if dp[i] < 0:
            continue
        dp[i] += pl(dp[i-1])
        if i >= 2:
            dp[i] += pl(dp[i-2])
        dp[i] %= MOD
    print(max(dp[-1], 0))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N, M = map(int,input().split())
DP = [0 for i in range(N+1)]
DP[0]=1
for i in range(M):
    DP[int(input())] = None
for i in range(N):
    if 0<i and DP[i+1]!=None and DP[i-1]!=None:
        DP[i+1]+=DP[i-1]
    if DP[i+1]!=None and DP[i]!=None:
        DP[i+1]+=DP[i]
print(DP[N]%1000000007)

Submission status: Accepted

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

dp = [0] * (n+1)
dp[0] = 1

issafe = [True] * (n+1)
for a in ai:
    issafe[a] = False

if issafe[1]:
    dp[1] = 1

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

print(dp[n])

Submission status: Accepted

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

mod = 10 ** 9 + 7
for i in range(M):
    a1 = int(input())
    a[a1] = -1
    
for i in range(2,N+1):
    if a[i] == -1:
        continue
    else:
        a[i] = (max(a[i-1], 0) + max(a[i-2], 0)) % mod
        
print(a[N])

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
a = set([int(input()) for _ in range(m)])
mod = 1000000007
dp = [0] * (n+1)
dp[0] = 1#0段目へ行く移動方法は1通りしかない
if 1 not in a:#もし階段がぶっ壊れてるリストに1段目が入っていないならば1段目へ行く移動方法は1通り、そうでないなら0通り
    dp[1] = 1
else:
    dp[1] = 0
for i in range(2,n+1):#2段目から調べていく
    if i in a:#現在のi段目がぶっ壊れリストに含まれてるなら何もせず飛ばす
        continue
    dp[i] = dp[i-1] + dp[i-2]#フィボナッチで処理
    dp[i] %= mod#modで割っていく
print(dp[n])#n+1番目を出力する

Submission status: Accepted

Solution code:
MOD = 10 ** 9 + 7

N, M = map(int, input().split())
A = [int(input()) for _ in range(M)]
A.append(N + 1)
S = [0] * (N + 2)


S[0] = 1
i = 1

for a in A:
    while i < a:
        S[i] = (S[i - 1] + S[i - 2]) % MOD
        i += 1
    i += 1

print(S[N])

Submission status: Accepted

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

dp[0] = 1
for i in range(1,N+1):
  dp[i] = (dp[i-1] + dp[i-2])%(10**9+7)
  if i in a_list:
    dp[i] = 0
print(dp[N])

Submission status: Accepted

Solution code:
mod = 1000000007
n,m = map(int, input().split(" "))
a = set([int(input()) for i in range(m)])
ans = [0]*(n+1)
ans[0] = 1
for j in range(1,n+1):
  if j in a:
    ans[j] = 0
  else:
    ans[j] = (ans[j-1] + ans[j-2])%mod
print(ans[-1])

Submission status: Accepted

Solution code:
n,m = map(int,input().split())

check = [1]*(n+1)
check.append(0)
check.append(0)
for i in range(m):
    a = int(input())
    check[a] = 0
    

count = [0]*(n+2)

mod = 10**9+7
if check[0]==1:
    count[0] = 1
    
elif count[0] == 0:
    count[1] = 1

for i in range(1,n+2):
    count[i] += count[i-1] + count[i-2]
    count[i] %= mod
    if check[i] == 0:
        count[i] = 0
    
    
print(count[n]%mod)

Submission status: Accepted

Solution code:
from sys import stdin
import sys
##  input functions for me
def rsa(sep = ''):
    if sep == '' :
        return input().split() 
    else: return input().split(sep)
def rip(sep = ''):
    if sep == '' :
        return map(int, input().split()) 
    else: return map(int, input().split(sep))
def ria(sep = ''): 
    return list(rip(sep))
def ri(): return int(input())
def rd(): return float(input())
def rs(): return input()
##
def main():
    N, M = rip()
    A = [ri() for i in range(M)]

    fbd = [False] * (N + 1)
    for n in A: fbd[n] = True
    dp = [0] * (N + 1)
    dp[0] = 1
    mod = int(1e9 + 7)
    for i in range(N):
        for j in range(1,3):
            if i + j <= N and not fbd[i + j]:
                dp[i + j] += dp[i]
                if dp[i + j] >= mod: dp[i + j] -= mod
    
    print(dp[N])
    

if __name__ == "__main__":
    main()

Submission status: Accepted

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

mod = 1000000007
brok = [False] * (n+1)

for i in a:
    brok[i] = True

dp = [0] * (n+2)
dp[n] = 1

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

print(dp[0])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
a=set([int(input()) for i in range(m)])#setにしないとTLEになる
dp=[0]*(n+1)
dp[0]=1
for i in range(1,n+1):
    dp[i]=(dp[i-1]+dp[i-2])%(10**9+7)
    if i in a:
        dp[i]=0
print(dp[n])
# 入力
# 6 1
# 3

Submission status: Accepted

Solution code:
N, M = map(int,input().split())
alist = list()
for _ in range(M):
    alist.append(int(input()))


li = {}
li[0] = 1

for i in range(1,N+1):
    if len(alist)>=1 and i ==  alist[0]:
        li[i] = 0
        alist.pop(0)
    else:
        if i == 1:
            li[i] = 1
        else:
            li[i] = ((li[i-1] + li[i-2])%(10**9+7))
print(li[N]%(10**9+7))

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
a=0
if m!=0:
    a=int(input())
    
b=1
s=[1]*(n+1)
for i in range(1,n+1):
    if i!=a:
        if i-2>=0:
            s[i]=(s[i-1]+s[i-2])%1000000007
        else:
            s[i]=s[i-1]%1000000007
    elif b!=m:
        s[i]=0
        a=int(input())
        b+=1
    else:
        s[i]=0
print(s[n])

Submission status: Accepted

Solution code:
from itertools import accumulate
n,m=map(int,input().split())
dp=[0]*(n+1)
List=[int(input()) for i in range(m)]
List.sort()
step=0

dp[0]=1
dp[1]=1

if(m>0 and List[0]==1):
    dp[1]=0
    step+=1
for i in range(2,n+1):
    # print(i,step)
    if(step<m and i==List[step]):
        step+=1
        dp[i]=0
    else:
        dp[i]=dp[i-2]+dp[i-1]
# print(List)
# print(dp)
print(dp[n]%((10**9)+7))

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
a=set(int(input()) for _ in range(m))
dp=[0]*(n+2)
dp[0]=1
for i in range(n):
    if i in a:
        continue
    dp[i+1]+=dp[i]
    dp[i+2]+=dp[i]
print(dp[n]%1000000007)

Submission status: Accepted

Solution code:
N, M = map(int,input().split())
a = set()
for _ in range(M):
    A = int(input())
    a.add(A)
dp = [0 for _ in range(N + 2)]
dp[0] = 1
for i in range(N):
    if i in a:
        continue
    dp[i + 1] += dp[i]
    dp[i + 2] += dp[i]
    if dp[i + 1] > 1000000007:
        dp[i + 1] %= 1000000007
        dp[i + 2] %= 1000000007
print(dp[N] % 1000000007)

Submission status: Accepted

Solution code:
mod = 10**9+7
n, m = map(int, input().split())
stairs = [0]*(n+1)
broken = []
stairs[0] = 1

def binSearch(broken, e):
    l, r = 0, m-1

    while l <= r:
        mid = (l+r)//2

        if broken[mid] > e:
            r = mid - 1
        elif broken[mid] < e:
            l = mid + 1
        else:
            return True
    return False


for i in range(m):
    b = int(input())
    if broken and b-1 == broken[-1]:
        print(0)
        exit(0)
    broken.append(b)

for i in range(n+1):
    if binSearch(broken, i):
        continue
    if i >= 2:
        stairs[i] = stairs[i-1] + stairs[i-2]
    elif i == 1:
        stairs[i] = stairs[i-1]

print(stairs[-1]%mod)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

MOD = 1000000007


def main():
    n, m = [int(i) for i in input().split()]
    a = {int(input()) for _ in range(m)}
    steps = [0] * (n + 1)
    steps[0] = 1

    for now in range(n):
        for next_ in range(now + 1, min(now + 2, n) + 1):
            if next_ not in a:
                steps[next_] += steps[now] % MOD
                steps[next_] %= MOD
    print(steps[-1])


if __name__ == '__main__':
    main()

Submission status: Accepted

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

x = [0] * (n + 5)
mod = 1000000007
x[0] = 1
for i in range(1, n + 1):
    x[i] = x[i - 1] + x[i - 2]
    x[i] %= mod
    if i in a: x[i] = 0
print(x[n])

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
A=[]
B=[True]*(N+1)
DP=[0]*(N+1)
DP[0]=1
for i in range(M):
  A.append(int(input()))
for i in range(M):
  B[A[i]]=False
#print(B)

for i in range(1,N+1):
  if B[i]==False:
    DP[i]=0
  else:
    if i==1:
      DP[i]=DP[i-1]
    else:
      DP[i]=(DP[i-1]+DP[i-2])%1000000007
if DP[N]==0:
  print(0)
else:
  print(DP[N])

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
A=[]
B=[True]*(N+1)
DP=[0]*(N+1)
DP[0]=1
for i in range(M):
  A.append(int(input()))
for i in range(M):
  B[A[i]]=False
#print(B)

for i in range(1,N+1):
  if B[i]==False:
    DP[i]=0
  else:
    if i==1:
      DP[i]=DP[i-1]
    else:
      DP[i]=DP[i-1]+DP[i-2]
if DP[N]==0:
  print(0)
else:
  print(DP[N]%1000000007)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())

S = [1] * (n + 1)
for _ in range(m):
    a = int(input())
    S[a] = 0

mod = 10**9 + 7
for i in range(2, n + 1):
    if S[i] != 0:
        S[i] = (S[i - 1] + S[i - 2]) % mod

ans = S[n]
print(ans)

Submission status: Accepted

Solution code:
import numpy as np

n, m = map(int, input().strip().split())
array = [int(input()) for _ in range(m)]
is_broken = np.zeros(n + 1, dtype=np.bool)
for a in array:
    is_broken[a] = 1

a0 = 0
a1 = 1

if n == 1:
    if is_broken[n]:
        print(0)
    else:
        print(1)

else:
    for i in range(1, n + 1):
        if is_broken[i]:
            a2 = 0
        else:
            a2 = (a1 + a0) % 1000000007

        a0 = a1
        a1 = a2

    print(a1)