Problem p03013 (python)

Fixed submission:
n, m = map(int, input().split())
a = [True for _ in range(n + 1)]
for _ in range(m):
    a[int(input())] = False

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

for now in range(n):
    for next in range(now + 1, min(n + 1, now + 3)):
        if a[next]:
            dp[next] += dp[now]
            dp[next] %= 1000000007

print(dp[n])

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

dp = [-1 for _ in range(n + 1)]

def checker(s, g):
    if s > g:
        return 0
    elif s == g:
        return 1
    else:
        if dp[g - s] != -1:
            return dp[g - s]
        else:
            ret = checker(s + 1, g) + checker(s + 2, g)
            dp[g - s] = ret
            return ret

if m == 0:
    c = checker(0, n)
else:
    s = 0
    g = a[0] - 1
    if g - s > 0:
        c = checker(s, g)
    else:
        c = 1
    if m == 1:
        s = a[0] + 1
        g = n
    else:
        for i in range(1, m):
            if a[i - 1] + 1 == a[i]:
                c = 0
                break
            else:
                s = a[i - 1] + 1
                g = a[i] - 1
                if g - s > 0:
                    c *= checker(s, g)
                s = a[m - 1] + 1
                g = n
    if g - s > 0:
        c *= checker(s, g)

print(c % 1000000007)

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

dp = [-1 for _ in range(n)]

def checker(s, g):
    if s > g:
        return 0
    elif s == g:
        return 1
    else:
        if dp[g - s] != -1:
            return dp[g - s]
        else:
            ret = checker(s + 1, g) + checker(s + 2, g)
            dp[g - s] = ret
            return ret

if m == 0:
    c = checker(0, n)
else:
    s = 0
    g = a[0] - 1
    if g - s > 0:
        c = checker(s, g)
    else:
        c = 1
    if m == 1:
        s = a[0] + 1
        g = n
    else:
        for i in range(1, m):
            if a[i - 1] + 1 == a[i]:
                c = 0
                break
            else:
                s = a[i - 1] + 1
                g = a[i] - 1
                if g - s > 0:
                    c *= checker(s, g)
                s = a[m - 1] + 1
                g = n
    if g - s > 0:
        c *= checker(s, g)

print(c % 1000000007)

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

dp = [-1 for _ in range(n)]

def checker(s, g):
    if s > g:
        return 0
    elif s == g:
        return 1
    else:
        if dp[g - s] != -1:
            return dp[g - s]
        else:
            ret = checker(s + 1, g) + checker(s + 2, g)
            dp[g - s] = ret
            return ret

s = 0
g = a[0] - 1
if g - s > 0:
    c = checker(s, g)
else:
    c = 1
for i in range(1, m):
    if a[i - 1] + 1 == a[i]:
        c = 0
        break
    else:
        s = a[i - 1] + 1
        g = a[i] - 1
        if g - s > 0:
            c *= checker(s, g)
        s = a[m - 1] + 1
        g = n
if g - s > 0:
    c *= checker(s, g)

print(c % 1000000007)

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

def checker(s, g):
    if s > g:
        return 0
    elif s == g:
        return 1
    else:
        return checker(s + 1, g) + checker(s + 2, g)

s = 0
g = a[0] - 1
if g - s > 0:
    c = checker(s, g)
else:
    c = 1
for i in range(1, m):
    if a[i - 1] + 1 == a[i]:
        c = 0
        break
    else:
        s = a[i - 1] + 1
        g = a[i] - 1
        if g - s > 0:
            c *= checker(s, g)
        s = a[m - 1] + 1
        g = n
if g - s > 0:
    c *= checker(s, g)

print(c % 1000000007)