Problem p03013 (python)

Fixed submission:
N, M = map(int, input().split())
a = [int(input()) for _ in range(M)]
dp = [0]*(N+1)
for i in a:
    dp[i] = -1

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

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(200000)
N, M = map(int, input().split())
if N == 1:
    print(1) 
    
elif M == 0:
    print(dp[N-1])
    
else:
    dp = [0]*N
    dp[0] = 1
    dp[1] = 2
    for i in range(N-2):
        dp[i+2] = dp[i]+dp[i+1]
        
    a = [int(input()) for _ in range(M)]
    
    for i in range(M-1):
        if a[i+1] == a[i] + 1:
            ans = 0
            break
    else:
        if a[0] == 1:
            ans == 1
        else:
            ans = dp[a[0]-2]
                
    for i in range(M-1):
        if a[i+1]-a[i] >= 3:
            ans *= dp[a[i+1]-a[i]-3]
    if N-a[M-1]-2 >= 0:
        ans *= dp[N-a[M-1]-2] 
    print(ans%1000000007)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10000)
N, M = map(int, input().split())

dp = [0]*(N+2)
dp[0] = 1
dp[1] = 2
for i in range(N):
    dp[i+2] = dp[i]+dp[i+1]
        
if M == 0:
    print(dp[N-1])
        
else:
    a = [int(input()) for _ in range(M)]
    
    for i in range(M-1):
        if a[i+1] == a[i] + 1:
            ans = 0
            break
    else:
        if a[0] == 1:
            ans == 1
        else:
            ans = dp[a[0]-2]
                
    for i in range(M-1):
        if a[i+1]-a[i] >= 3:
            ans *= dp[a[i+1]-a[i]-3]
    if N-a[M-1]-2 >= 0:
        ans *= dp[N-a[M-1]-2] 
    print(ans%1000000007)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
if N <= 2 and M != 0:
    print(N-1)
elif N <= 2:
    print(N)
    
else:
    dp = [0]*N
    dp[0] = 1
    dp[1] = 2
    for i in range(N-2):
        dp[i+2] = dp[i]+dp[i+1]
        
    if M == 0:
        print(dp[N-1])
        
    else:
        a = [int(input()) for _ in range(M)]
    
        for i in range(M-1):
            if a[i+1] == a[i] + 1:
                ans = 0
                break
        else:
            if a[0] == 1:
                ans == 1
            else:
                ans = dp[a[0]-2]
                
        for i in range(M-1):
            if a[i+1]-a[i] >= 3:
                ans *= dp[a[i+1]-a[i]-3]
        if N-a[M-1]-2 >= 0:
            ans *= dp[N-a[M-1]-2] 
        print(ans%1000000007)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
if N == 1:
    print(1) 
    
elif M == 0:
    print(dp[N-1])
    
else:
    dp = [0]*N
    dp[0] = 1
    dp[1] = 2
    for i in range(N-2):
        dp[i+2] = dp[i]+dp[i+1]
        
    a = [int(input()) for _ in range(M)]
    
    for i in range(M-1):
        if a[i+1] == a[i] + 1:
            ans = 0
            break
    else:
        if a[0] == 1:
            ans == 1
        else:
            ans = dp[a[0]-2]
                
    for i in range(M-1):
        if a[i+1]-a[i] >= 3:
            ans *= dp[a[i+1]-a[i]-3]
    if N-a[M-1]-2 >= 0:
        ans *= dp[N-a[M-1]-2] 
    print(ans%1000000007)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
a = [int(input()) for _ in range(M)]

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

for i in range(M-1):
    if a[i+1] == a[i] + 1:
        print(0)
        break
else:
    if a[0] == 1:
        ans = 1
    else:
        ans = dp[a[0]-2]
    for i in range(M-1):
        if a[i+1]-a[i] >= 3:
            ans *= dp[a[i+1]-a[i]-3]
    if N-a[M-1]-2 >= 0:
        ans *= dp[N-a[M-1]-2] 
    print(ans%1000000007)