Problem p03013 (python)

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

b = [0 for i in range(n+1)]

for mi in range(m):
    b[int(input())] = 1
cnt = 0
s = [0 for i in range(n+1)]
s[0] = 1
if b[1] == 0:
    s[1] = 1
else:
    s[1] = 0
for ni in range(2,n+1):
    if b[ni] == 0:
        s[ni] = (s[ni-1] + s[ni-2]) % 1000000007
    else:
        s[ni] = 0
print(s[n])

Buggy submission (verdict: Runtime Error):
n, m = [int(i) for i in input().split()]
a = [-1]
 
MAX = 100000
MOD = 1000000007
fac = [1 for i in range(MAX)]
finv = [1 for i in range(MAX)]
inv = [1 for i in range(MAX)]
for i in range(2, MAX):
    fac[i] = fac[i-1] * i % MOD
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD
    finv[i] = finv[i - 1] * inv[i] % MOD
 
def COM(n , r):
    if n < r:
        return 0
    if n < 0 or r < 0:
        return 0
    return fac[n] * (finv[r]* finv[n-r]%MOD)%MOD
 
for mi in range(m):
    a.append(int(input()))
a.append(n+1)
 
ans = 1
for mi in range(1, m+2):
    if a[mi] == a[mi-1]:
        break
    elif a[mi] == a[mi-1] + 1:
        ans = 0
        break
    k = a[mi] - a[mi-1] - 2
    max_2 = k//2
    cnt = 0
    for i in range(max_2+1):
        cnt += COM(k-i, i)
    ans = ans * cnt % 1000000007
    if ans == 0:
        break
 
print(int(ans))

Buggy submission (verdict: Runtime Error):
n, m = [int(i) for i in input().split()]
 
 
def countPattern(s, cnt):
    if s > 1:
        cnt = countPattern(s-2, cnt)
        cnt = countPattern(s-1, cnt)
        return cnt
    else:
        return cnt + 1
 
 
ans = 1
a_pre = -1
for mi in range(m):
    a = int(input())
    if a == a_pre:
        break
    elif a == a_pre + 1:
        ans = 0
    ans = ans * countPattern(a-a_pre-2, 0) % 1000000007
    a_pre = a
 
a = n + 1
ans = ans * countPattern(a - a_pre - 2, 0) % 1000000007
 
print(ans)

Buggy submission (verdict: Runtime Error):
n, m = [int(i) for i in input().split()]
a = [-1]

MAX = 100000
MOD = 1000000007
fac = [1 for i in range(MAX)]
finv = [1 for i in range(MAX)]
inv = [1 for i in range(MAX)]
for i in range(2, MAX):
    fac[i] = fac[i-1] * i % MOD
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD
    finv[i] = finv[i - 1] * inv[i] % MOD

def COM(n , r):
    if n < r:
        return 0
    if n < 0 or r < 0:
        return 0
    return fac[n] * (finv[r]* finv[n-r]%MOD)%MOD

for mi in range(m):
    a.append(int(input()))
a.append(n+1)

ans = 1
for mi in range(1, m+2):
    if a[mi] == a[mi-1]:
        break
    elif a[mi] == a[mi-1] + 1:
        ans = 0
        break
    k = a[mi] - a[mi-1] - 2
    max_2 = k//2
    cnt = 0
    for i in range(max_2+1):
        cnt += COM(k-i, i)
    ans = ans * cnt % 1000000007
    if ans == 0:
        break

print(int(ans))

Buggy submission (verdict: Runtime Error):
from functools import lru_cache

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

@lru_cache(maxsize=10000)
def countPattern(s, cnt):
    if s > 1:
        cnt = countPattern(s-2, cnt)
        cnt = countPattern(s-1, cnt)
        return cnt
    else:
        return cnt + 1


ans = 1
a_pre = -1
for mi in range(m):
    a = int(input())
    if a == a_pre:
        break
    elif a == a_pre + 1:
        ans = 0
    ans = ans * countPattern(a-a_pre-2, 0) % 1000000007
    a_pre = a

a = n + 1
ans = ans * countPattern(a - a_pre - 2, 0) % 1000000007

print(ans)

# TLE

Buggy submission (verdict: Runtime Error):
n, m = [int(i) for i in input().split()]


def countPattern(s, cnt):
    if s > 1:
        cnt = countPattern(s-2, cnt)
        cnt = countPattern(s-1, cnt)
        return cnt
    else:
        return cnt + 1


ans = 1
a_pre = -1
for mi in range(m):
    a = int(input())
    if a == a_pre:
        break
    elif a == a_pre + 1:
        ans = 0
    ans = ans * countPattern(a-a_pre-2, 0) % 1000000007
    a_pre = a

a = n + 1
ans = ans * countPattern(a - a_pre - 2, 0) % 1000000007

print(ans)