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:
import sys

sys.setrecursionlimit(1000000)

MOD = 1000000007

state = [-1 for i in range(100010)]

def step_state(n, broken):
    if state[n] != -1:
        return state[n]

    if n == 0:
        state[0]=1
        return 1
    elif n == 1:
        if broken[1]:
            state[1]=0
            return 0
        else:
            state[1]=1
            return 1
    else:
        if broken[n - 1] and broken[n - 2]:
            state[n]=0
            return 0
        elif broken[n - 1]:
            state[n]=step_state(n-2, broken) % MOD
            return state[n]
        elif broken[n-2]:
            state[n] = step_state(n-1, broken) % MOD
            return state[n]
        else:
            state[n] = (step_state(n-1, broken)+step_state(n-2, broken)) % MOD
            return state[n]


if __name__ == '__main__':
    n, m = map(int, input().split())
    a = set([int(input()) for i in range(m)])
    broken = [False] * (n+1)
    for i in range(n+1):
        if i in a:
            broken[i] = True

    answer = step_state(n, broken)

    print(answer)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(200010)

n, m = map(int, input().split())
a = [int(input()) for i in range(m)]
b = [0]*(n+1)
dp = [-1]*(n+1)
for e in a:
    b[e] = 1
dp[0] = 1


def solve(k):
    if(b[k] == 1):
        return 0
    if(dp[k] != -1):
        return dp[k]
    if(k < 0):
        return 0
    tmp = solve(k-1)+solve(k-2)
    dp[k] = tmp % 1000000007
    return tmp


print(solve(n) % (1000000007))

Submission status: Accepted

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

Submission status: Accepted

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

MOD = pow(10, 9) + 7

dp = [0] * (n+1)

dp[0] = 1

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

c = 1

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

print(dp[-1] % MOD)

Submission status: Accepted

Solution code:
import sys
 
sys.setrecursionlimit(1000000)
n, m, *a = map(int, open(0).read().split())
dp = [1] + [-1] * n
dp[1] = 1
for i in a:
    dp[i] = 0
 
def count(n):
    if dp[n] != -1:
        return dp[n]
    dp[n] = (count(n - 1) + count(n - 2)) % (10**9 + 7)
    return dp[n]
 
 
print(count(n))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

MOD=10**9+7
N,M=map(int,input().split())
bad=set(map(int,sys.stdin))

a,b=0,1
for i in range(1,N+1):
    if i in bad:
        a,b=b,0
        if a==0:
            break
    else:
        a,b=b,(a+b)%MOD

print(b)

Submission status: Accepted

Solution code:
import sys

N,M=map(int,input().split())
bad=set(map(int,sys.stdin))
MOD=10**9+7

a,b=0,1
for i in range(1,N+1):
    if i in bad:
        a,b=b,0
        if a==0:
            break
    else:
        a,b=b,(a+b)%MOD

print(b)

Submission status: Accepted

Solution code:
import sys
N,M=map(int,input().split())
S=set(map(int,sys.stdin))

a,b=0,1
for i in range(1,N+1):
    if i in S:
        a,b=b,0
    else:
        a,b=b,a+b

print(b%(10**9+7))

Submission status: Accepted

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

dp=[0]*(N+1)
dp[0]=1
for _ in range(M):
    a=int(input())
    dp[a]=-1

for i in range(1,N+1):
    if dp[i]==-1:
        continue
    if dp[i-1]!=-1:
        dp[i]+=dp[i-1]
    if i>1 and dp[i-2]!=-1:
        dp[i]+=dp[i-2]

if dp[-1]==-1:
    print(0)
else:
    print(dp[-1]%(10**9+7))

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
br=set([int(input()) for _ in range(M)])
dp=[0]*(N+1)
dp[0]=1
if not 1 in br:
    dp[1]=1
for i in range(2,N+1):
    if not i in br:
        dp[i]+=(dp[i-1]+dp[i-2])%1000000007
print(dp[-1])

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
ais = []
for _ in range(m):
    ai = int(input())
    ais.append(ai)
dp = [0]*(n+1)
dp[0]=1
if len(ais)>0 and ais[0]==1:
  dp[1]=0
  ais.pop(0)
else:
  dp[1]=1
for i in range(2,n+1):
    if len(ais)>0 and ais[0]==i:
        dp[i] = 0
        ais.pop(0)
    else:
        dp[i] = dp[i-1] + dp[i-2]
print(dp[n]%1000000007)

Submission status: Accepted

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

ans =[1] + [1] + [-1] * (n-1)

for i in lis:
    ans[i] = 0


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

print(ans[n])

Submission status: Accepted

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

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

print(dp[-1] % mod)

Submission status: Accepted

Solution code:
import bisect, copy, heapq, math
from math import inf
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
def celi(a,b):
    return -(-a//b)
sys.setrecursionlimit(5000000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

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

dic={}
for i in range(m):
    dic[a[i]]=1
dp=[0]*(n+2)

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

Submission status: Accepted

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

dp=[1]+['']*n

for i in a:
  dp[i]=0

if dp[1]=='':
  dp[1]=1
  

for i in range(2,n+1):
  if dp[i]=='':
    dp[i]=(dp[i-1]+dp[i-2])%(10**9+7)

print(dp[-1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
broken = set()
for i in range(M):
    broken.add(int(input()))
dp = [0 for i in range(N+1)]
dp[0] = 1
if 1 not in broken:
    dp[1] = 1
for i in range(2,N+1):
    if i in broken:
        dp[i] = 0
    else:
        dp[i] = dp[i-1] + dp[i-2]
        dp[i] %= 1000000007
print(dp[N])

Submission status: Accepted

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

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

def fib(x):
  if memo[x] == -1:
    memo[x] = fib(x-1) + fib(x-2)
  return memo[x]

def fib2(x):
  if x <= 1:
    return memo[x]
  else:
    for i in range(x - 1):
      if memo[i + 2] == 0:
        continue
      memo[i + 2] = memo[i] + memo[i + 1]
    return memo[x]

# print(fib2(n))
# print(memo)
print(fib2(n) % 1000000007)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
broken = set()
for i in range(M):
    broken.add(int(input()))
if N == 1:
    if 1 in broken:
        print(0)
    else:
        print(1)
elif N == 2:
    if 2 in broken:
        print(0)
    elif 1 in broken:
        print(1)
    else:
        print(2)
else:
    dp = [0 for i in range(N+1)]
    if 1 not in broken:
        dp[1] = 1
    if 2 not in broken:
        dp[2] = dp[1] + 1
    for i in range(3,N+1):
        if i in broken:
            dp[i] = 0
        else:
            dp[i] = dp[i-1] + dp[i-2]
            dp[i] %= 1000000007
    print(dp[N])

Submission status: Accepted

Solution code:
LI = lambda: list(map(int, input().split()))

N, M = LI()
A = [int(input()) for _ in range(M)]

MOD = 10 ** 9 + 7


def main():
    s = set(A)
    dp = [0] * (N + 1)
    dp[0] = 1
    for i in range(1, N + 1):
        if i in s:
            continue
        v = dp[i - 1]
        if i >= 2:
            v += dp[i - 2]
        dp[i] = v % MOD
    
    ans = dp[-1]
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
n,m=map(int,input().split())
a=[]
d=0
for i in range(m):
    a.append(int(input()))
a.append(0)
a.append(0)
a.append(0)
ans=[]
for i in range(m-1):
    if a[i+1]-a[i]==1:
        print(0)
        sys.exit()
ans=[0 for i in range(n+5)]
ans[1]=1
ans[2]=2

if a[0]==1:
    ans[1]=0
    ans[2]=1
    d+=1
if a[0]==2 or a[1]==2:
    ans[2]=0
    d+=1

for i in range(1,n+3):
    if i+2==a[d]:
        ans[i+2]=0
        d+=1
    else:
        ans[i+2]=ans[i+1]%1000000007+ans[i]%1000000007
   
print(ans[n]%1000000007)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(100000)
d = {0:1, 1:1, 2:2}
def countcombi(n):
    if n in d:
        return d[n]
    else:
        d[n] = countcombi(n-1)+countcombi(n-2)
        return d[n]
N, M = list(map(int,input().rstrip().split()))
a_now = 0
a_before = 0
ans = 1
for _ in range(M):
    a_now = int(input().rstrip())
    if a_now-a_before == 0 and a_before != 0:
        print(0)
        break
    ans = (ans * countcombi(a_now-a_before-1)) % 1_000_000_007
    a_before = a_now + 1
else:
    a_now = N
    ans = (ans * countcombi(a_now-a_before)) % 1_000_000_007
    print(ans)

Submission status: Accepted

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

for i in range(2,N+1):
    if not i in br:
        dp[i]+=(dp[i-1]+dp[i-2])%1000000007
print(dp[-1])

Submission status: Accepted

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

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

dp[0]=1

dp[1]=1

for i in a:
  dp[i]=0
  

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

Submission status: Accepted

Solution code:
n,m,*a=map(int,open(0).read().split())
a=set(a)
mod=10**9+7

dp=[0]*(n+1)

dp[0]=1
dp[1]=0 if 1 in a else 1

for st in range(2,n+1):
    if st in a:
        continue
    
    dp[st]=dp[st-1]+dp[st-2]
    dp[st]%=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)
for a in A:
  L[a]=-1
L[0] = 1
L[1] += 1
for i in range(2, N+1):
  if L[i]==-1:
    L[i]=0
  else:
    L[i] = L[i-1]+ L[i-2]
print(L[-1]%(10**9+7))

Submission status: Accepted

Solution code:
def Fib(n):
    a, b = 1, 1
    if n == 1:
        return a
    elif n == 2:
        return b
    else:
        for i in range(n-2):
            a, b = b, a + b
        return b

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

for i in range(len(a)-1):
    if a[i+1] == a[i]+1:
        print(0)
        exit()
x = []
temp=0
for i in range(m):
    x.append(a[i]-temp-1)
    temp = a[i]+1
x.append(n-temp)

temp = 1
div = 1000000007

for i in x:
    temp = (temp*Fib(i+1))%div

print(temp)

Submission status: Accepted

Solution code:
import sys
n,m=map(int,input().split())
if m != 0:
  a=set(map(int,sys.stdin.read().split()))
else:
  a=set()

modx=10**9+7

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

for i in range(n+1):
  if i+1 not in a:
    dp[i+1]= (dp[i]+dp[i+1]) % modx
  if i+2 not in a:
    dp[i+2]= (dp[i]+dp[i+2]) % modx

print(dp[n])

Submission status: Accepted

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

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

for i in li:
    dp[i] = 0

for i in range(1,n+1):
    if dp[i] == 0:
        continue
    
    if i == 1:
        dp[1] = 1
    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=set([int(input()) for j in range(m)])
dp=[0]*(n+1)
dp[0]=1
if not 1 in a:
    dp[1]=1
else:
    dp[1]=0
for i in range(n-1):
    if i+2 in a:
        dp[i+2]=0
    else:
        dp[i+2]=(dp[i+1]+dp[i])%(10**9+7)
print(dp[n])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# 問題：https://atcoder.jp/contests/abc126/tasks/abc129_c

mod = 1000000007
N, M = map(int, input().strip().split())
a = [int(input()) for _ in range(M)]
a.append(N+1)

def fibonacci(x):
    a = 1
    b = 1
    if x <= 2:
        return a
    else:
        for _ in range(x-2):
            tmp = a
            a = b
            b = tmp + b
        return b

res = 1
prev_a = -1
for cur_a in a:
    if  cur_a - prev_a == 1:
        res = 0
        break
    res *= fibonacci(cur_a - prev_a - 1) % mod
    res %= mod
    prev_a = cur_a
    continue

print(res)

Submission status: Accepted

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

p = 10**9 +7
ans = [0]*(n+1)
ans[0] = 1
ans[1] = 1

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

for i in range(1,n):
    if broken[i] == -1:
        ans[i] = 0
        ans[i+1] = ans[i-1]%p
    else:
        ans[i+1] = (ans[i-1] + ans[i])%p

print(ans[-1])

Submission status: Accepted

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

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

print(dp[n] % 1000000007)

Submission status: Accepted

Solution code:
MOD=10**9+7
n,m=map(int,input().split())
a=set([int(input()) for _ in range(m)])
if 1 in a:
  ans=[1,0]
else:
  ans=[1,1]

for i in range(1,n):
  if i+1 in a:
    ans.append(0)
  else:
    s=(ans[-1]+ans[-2])%MOD
    ans.append(s)
print(ans[-1]%MOD)

Submission status: Accepted

Solution code:
import sys
from functools import lru_cache
sys.setrecursionlimit(10**9)
MOD=10**9+7
n,m=map(int,input().split())
a=set([int(input()) for _ in range(m)])
if 1 in a:
  ans=[1,0]
else:
  ans=[1,1]

@lru_cache(maxsize=None)
def cnt(x):
  if x<2:
    return ans[x]
  if x in a:
    return 0
  else:
    return (cnt(x-1)+cnt(x-2))%MOD

print(cnt(n))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
MOD=10**9+7
n,m=map(int,input().split())
a=set([int(input()) for _ in range(m)])
if n==1:
  print(1)
  exit()
if 1 in a and 2 in a:
  print(0)
  exit()
elif 1 in a:
  ans=[0,1]
elif 2 in a:
  ans=[1,0]
else:
  ans=[1,2]

for i in range(2,n):
  if i+1 in a:
    ans.append(0)
  else:
    s=(ans[-1]+ans[-2])%MOD
    ans.append(s)
print(ans[-1]%MOD)

Submission status: Accepted

Solution code:
import sys
from functools import lru_cache
sys.setrecursionlimit(10**9)
MOD=10**9+7
n,m=map(int,input().split())
a=set([int(input()) for _ in range(m)])
if n==1:
  print(1)
  exit()
if 1 in a and 2 in a:
  print(0)
  exit()
elif 1 in a:
  ans=[0,0,1]
elif 2 in a:
  ans=[0,1,0]
else:
  ans=[0,1,2]

@lru_cache(maxsize=None)
def cnt(x):
  if x<3:
    return ans[x]
  if x in a:
    return 0
  else:
    return (cnt(x-1)+cnt(x-2))%MOD

print(cnt(n))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m=map(int, input().split())
alist=[0]*(n+10)
for i in range(m):
  alist[int(input())]=-1
ans=True
alist[0]=1
for i in range(n):
  if alist[i]!=-1:
    if alist[i+1]!=-1 and alist[i+2]!=-1:
      alist[i+1]+=alist[i]
      alist[i+2]+=alist[i]
    elif alist[i+2]!=-1:
      alist[i+2]+=alist[i]
    elif alist[i+1]!=-1:
      alist[i+1]+=alist[i]
    else:
      ans=False
if ans:
  print(alist[n]%(10**9+7))
else:
  print(0)

Submission status: Accepted

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

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

    for m in range(0, M):
        i = int(input())
        s[i] = 0

    for n in range(2, N):
        if s[n] == 0:
            continue
        s[n] = s[n - 1] + s[n - 2]

    print((s[N-1] + s[N-2]) % 1000000007)

Submission status: Accepted

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

a = [0] * (n+2)
dp = [0] * (n+2)
mod = 1000000007

for i in range(m):
	num = int(input())
	a[num] = 1

dp[0]=1

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

print(dp[n]%mod)

Submission status: Accepted

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

a = [0] * (n+1)
dp = [0] * (n+1)
mod = 1000000007

for i in range(m):
	num = int(input())
	a[num] = 1

dp[0]=1

for i in range(1,n+1):
	if a[i] == 1:
		continue

	dp[i] += dp[i-1]
	if i>1:
		dp[i] += dp[i-2]

	dp[i] = dp[i] % mod

print(dp[n]%mod)

Submission status: Accepted

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

a = []
dp = []
mod = 1000000007

for i in range(100100):
	a.append(0)
	dp.append(0)

for i in range(m):
	num = int(input())
	a[num] = 1

dp[0]=1

for i in range(1,n+1):
	if a[i] == 1:
		continue

	dp[i] += dp[i-1]
	if i>1:
		dp[i] += dp[i-2]

	dp[i] = dp[i] % mod

print(dp[n]%mod)

Submission status: Accepted

Solution code:
mod = 10 ** 9 + 7

n, m = map(int, input().split())
A = [int(input()) for _ in range(m)]
not_wet = [True] * (n + 1)
for a in A:
    not_wet[a] = False
dp = [0] * (n + 1)
dp[0] = 1
for i in range(1, n + 1):
    if not_wet[i]:
        if i == 1:
            dp[i] = dp[i - 1] % mod
        else:
            dp[i] = dp[i - 1] + dp[i - 2] % mod
print(dp[n] % mod)

Submission status: Accepted

Solution code:
patterns = [None] * (10**5 + 10)
patterns[0] = 1
patterns[1] = 1
calcurated_until = 1
MOD = 10**9+7
def get_patterns(n):
  global calcurated_until, patterns
  if patterns[n] is None:
    for i in range(calcurated_until + 1, n + 1):
      patterns[i] = (patterns[i-1] + patterns[i-2])%MOD
    calcurated_until = n
  #print('p', n, patterns[n])
  return patterns[n]

def solve():
  N, M = map(int, input().split())
  A = [-1]
  for _ in range(M):
    A.append(int(input()))
  A.append(N+1)
  #print(A)
  
  ans = 1
  for a1, a2 in zip(A[:-1], A[1:]):
    #print(a1, a2)
    if a2 == a1+1:
      print('0')
      return
    #print('ans', ans)
    #print('get_patterns(a2 - a1 - 2)', get_patterns(a2 - a1 - 2))
    ans *= get_patterns(a2 - a1 - 2)
    #print('ans', ans)
    ans %= MOD
    #print('ans', ans)
  print(ans)
solve()

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
broken=set(int(input()) for _ in range(m))    

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

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

Submission status: Accepted

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

K=10**9+7

X=[0]*(N+1)
X[0]=1
X[1]=1*(1 not in A)

for i in range(2,N+1):
    if i not in  A:
        X[i]=(X[i-1]+X[i-2])%K
print(X[-1])

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
dp = [0 for _ in range(N+1)]
skip = {}

for _ in range(M):
    skip[int(input())] = 1

dp[1] = 1
if N >= 2:
    dp[2] = 2

if 1 in skip:
    dp[1] = 0
    if N >= 2:
        dp[2] = 1
if 2 in skip:
    if N >= 2:
        dp[2] = 0

for i in range(3, N+1):
    if i in skip:
        continue
    dp[i] = (dp[i-1] + dp[i-2]) % 1000000007

print(dp[N])

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
dp = [0 for _ in range(N+1)]
skip = {}

for _ in range(M):
    skip[int(input())] = 1

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

for i in range(2, N+1):
    if i in skip:
        continue
    dp[i] = (dp[i-1] + dp[i-2]) % 1000000007

print(dp[N])

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
dp = [0 for _ in range(N+1)]
skip = {}

for _ in range(M):
    skip[int(input())] = 1

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

for i in range(2, N+1):
    if i in skip:
        continue
    dp[i] += (dp[i-1] + dp[i-2]) % 1000000007

print(dp[N])

Submission status: Accepted

Solution code:
#https://atcoder.jp/contests/abc129/tasks/abc129_c
N,M = map(int,input().split())
dp = [[] for i in range(N)]
for i in range(M):
    dp[int(input())-1] = 0

for i in range(N):
    if dp[i] != 0:
        if i == 0:
            dp[i] = 1
        elif i == 1:
            dp[i] = dp[i-1] + 1
        else:
            dp[i] = dp[i-1] + dp[i-2]
        
print(dp[-1] % 1000000007)

Submission status: Accepted

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

for i in range(N):
  if i + 1 not in ng:
    dp[i + 1] += dp[i]
    dp[i + 1] %= 1000000007
  if i + 2 not in ng:
    dp[i + 2] += dp[i]
    dp[i + 2] %= 1000000007

print(dp[N])

Submission status: Accepted

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

for i in range(N):
  for j in range(1, 3):
    if (i + j) not in ng:
      dp[i + j] += dp[i]
      dp[i + j] %= 1000000007

print(dp[N])

Submission status: Accepted

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

for i in range(2, len(dp)):
  if i in ng:
    continue
  dp[i] += (dp[i - 2] + dp[i - 1])
  dp[i] %= 1000000007
  
print(dp[N])

Submission status: Accepted

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

def fib(n):
    if n == 0:
        return 0
    one = 1
    two = 1
    for _ in range(n-2):
        two,one = one + two,two
    return two

ans,now = 1,0
for i in range(M):
    a = int(input())
    ans *= fib(a - now)
    now = a+1
    if ans > 10**9+7:
        ans %= 10**9 + 7
ans *= fib(N - now + 1)
ans %= 10**9 + 7

print(ans)

Submission status: Accepted

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

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

for i in range(2,n+1):
  if i in a:
    continue

  dp[i] += dp[i-1] + dp[i-2]
  dp[i] = dp[i] % 1000000007
print(dp[n])

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
keep = [0] * (n + 1)
kep = [-1] * (n + 1)

for i in range(m):
    a = int(input())
    kep[a] = 0
keep[0] = 1
keep[1] = 0 if kep[1] == 0 else 1
for j in range(0, n - 1):
    keep[j + 2] = [0, keep[j] + keep[j + 1]][kep[j + 2]] % 1000000007
print(keep[n])

Submission status: Accepted

Solution code:
import math
import queue

n, m = map(int, input().split(" "))
aL = [int(input()) for _ in range(m)]

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

for a in aL:
    dp[a] = 0

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

print(dp[n] % 1_000_000_007)

# q = queue.Queue()
# q.put(0)

# cnt = 0
# while not q.empty():
#     c = q.get()
#     if dp[c] != -1:
#         cnt += dp[c]
#         continue
#     if c == n:
#         cnt += 1
#         continue
#     q.put(c + 1)
#     if c + 1 != n:
#         q.put(c + 2)
#     dp[c] = cnt

# def ppp(num):
#     cnt = 0
#     q = queue.Queue()
#     q.put(num)
#     while not q.empty():
#         c = q.get()
#         if dp[c] != -1:
#             cnt += dp[c]
#             continue
#         if c == num:
#             cnt += 1
#             continue
#         q.put(c + 1)
#         if c + 1 != num:
#             q.put(c + 2)
#         dp[c] = cnt
#     print(cnt)
#     return cnt

# cli = [aL[0] - 1]
# for i in range(1, m):
#     if abs(aL[i] - aL[i - 1]) == 1:
#         print(0)
#         exit()
#     cli.append(aL[i] - aL[i - 1] - 1)
# cli.append(n - aL[-1] - 1)

# ans = 1
# for c in cli:
#     ans = (ans * ppp(c)) % 1_000_000_007

# print(ans)

# dp = [-1] * (n + 1)
# def od(num):
#     if dp[num] != -1:
#         return dp[num]
#     q = queue.Queue()
#     q.put(num)
#     cnt = 0
#     while not q.empty():
#         c = q.get()
#         if c == 0:
#             cnt += 1
#             continue
#         if c != 1:
#             q.put(c - 2)
#         q.put(c - 1)
#     dp[num] = cnt
#     return cnt
# if m == 0:
#     print(od(n))
#     exit()
# cli = [aL[0] - 1]
# for i in range(1, m):
#     if abs(aL[i] - aL[i - 1]) == 1:
#         print(0)
#         exit()
#     cli.append(aL[i] - aL[i - 1] - 1)
# cli.append(n - aL[-1] - 1)
# print(cli)
# ans = 1
# for c in cli:
#     ans = (ans * od(c)) % 1_000_000_007
# print(ans % 1_000_000_007)

Submission status: Accepted

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

for i in range(1,N+1):
 if i in A: continue
 D[i]=(D[i-1]+D[i-2])%(10**9+7)
print(D[-1])

Submission status: Accepted

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

for i in range(1,N+1):
 if i in A: continue
 D[i]=D[i-1]+D[i-2]
print(D[-1] % (10**9+7))

Submission status: Accepted

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

A=set(A)
D=[0]*(N+1)
D[0]=1

direction=[1,2]

for i in range(1,N+1):
 if i in A: continue
 # print([abs(H[i]-H[i-a])+D[i-a] for a in [1,2]])
 cnt=0
 for d in direction:
    prv=i-d
    if 0<=prv and not(prv in A): 
        cnt=cnt+D[prv]
        #print(i, prv,D[prv])

 D[i]=cnt
print(D[-1] % 1000000007)

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)
dp[0] = 1
    
for i in range(1,n+1):
    if i in a:
        continue
    x = dp[i-1] 
    if i > 1:
        x += dp[i-2]
    dp[i] = x
ans = dp[n] % mod
print(ans)

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)
dp[0] = 1
    
for i in range(1,n+1):
    if i in a:
        continue
    x = dp[i-1] 
    if i > 1:
        x += dp[i-2]
    dp[i] = x % mod
ans = dp[n]
print(ans)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
a = [int(input()) for _ in range(m)]
ans = 1
MOD = 10**9+7
MAX = 10**5+1

fib = [0] * MAX
fib[0], fib[1] = 1, 2
for i, j in zip(a[:m-1], a[1:]):
    if j - i == 1:
        print(0)
        exit()

for i in range(2, MAX):
    fib[i] = fib[i-1] + fib[i-2]
    
for i in range(m+1):
    left = 0 if i == 0 else a[i-1] + 1
    right = n if i == m else a[i] - 1
    between = right - left
    if not between:
        continue
    ans *= fib[between-1]
    ans %= MOD
print(ans)

Submission status: Accepted

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

for n in range(1,N+1):
  if n not in A:
    dp[n] = (dp[n-2]+dp[n-1])%(10**9+7)

print(dp[-1])

Submission status: Accepted

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

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

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

for i in range(2, n + 1):
    dp[i] = a[i] * (dp[i-2] * a[i-2] + dp[i-1] * a[i-1])

print(dp[-1] % 1000000007)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def Fib(n):
    a, b = 0, 1
    if n == 1:
        return a
    elif n == 2:
        return b
    else:
        for i in range(n-2):
            a, b = b, a + b
        return b

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

    if m > 1:
        for i in range(m-1):
            if a[i+1]-a[i] <= 1:
                return 0
    elif m == 0:
        return Fib(n+2)%1000000007

    
    a = a + [n]
    l = [a[0]]
    for i in range(1, m):
        l.append(a[i]-a[i-1]-1)
    l = l + [a[-1]-a[-2]]
    ans = 1
    for i in l:
        ans *= Fib(i+1)

    return ans%1000000007


print(solve())

Submission status: Accepted

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

mod = 10**9 + 7
dp = [0] * (n+1)
dp[0] = 1
if A[1]:
  dp[1] = 1

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

print(dp[n])

Submission status: Accepted

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


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

# 行けない段
for ai in a:
    dp[ai] = -1

for i in range(1, N + 1):
    # 1段目だけ例外処理
    if i == 1:
        dp[1] += dp[0]

    elif i > 1 and dp[i] != -1:
        if dp[i - 2] != -1:
            dp[i] += dp[i - 2]
        if dp[i - 1] != -1:
            dp[i] += dp[i - 1]

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

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
MOD = 10**9+7

if m >= n//2+1:
    print(0)
    exit()

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

p = [0]*(n+1)
for i in range(1, n+1):
    if i == 1:
        if a[i]:
            p[i] += 1
        continue
    if i == 2:
        if a[i]:
            p[i] += 1

    if a[i]:
        p[i] += p[i-1] + p[i-2]
        p[i] %= MOD
print(p[n])