Problem p03013 (python)

Fixed submission:

N, M = input().split()

N = int(N)
M = int(M)
a = []
c = []

for i in range(M):

    anew = int(input())
    a.append(anew)

now_a = 0
a.append(-1)
ans = 0

for i in range( N + 1 ):

    if (i == 0):
        c.append(1)
        
    elif (i == 1):

        if (a[now_a] == i):
            c.append(0)
            now_a += 1
        else:
            c.append(1)

    else:

        if (a[now_a] == i):
            c.append(0)
            now_a += 1
        else:
            c.append( c[i - 1] + c[i - 2])
        

ans = c[N] % 1000000007

print (ans)

Buggy submission (verdict: Runtime Error):
    import math
    def cmb(n, r):
        return math.factorial(n)// ( math.factorial(n-r) * math.factorial(r) )
     
     
     
    N,M = input().split()
     
    N = int(N)
    M = int(M)
     
    a = []
    ans = 1
     
    for i in range(M):
        newa = int(input())
        a.append(newa)
     
    if (M != 0):
        for k in range(M-1):
            if (a[k+1] - a[k] == 1):
                ans = 0
                
        
        
        for i in range(M + 1):
        
     
            if (i == 0):
                dan = a[i] - 1
            elif (i == M):
                dan = N - a[i - 1] - 1
            else:
                dan = a[i] - a[i - 1] - 2
     
            abletwo = (dan - (dan % 2)) // 2
            now = 0
     
            if (dan != 0):
     
                for j in range(abletwo + 1):
     
                    now += cmb (dan - j , j )
     
            else:
                now = 1
            
            ans *= now
     
    else:
        ans = 0
        abletwo = (N - (N % 2)) // 2
     
        for j in range(abletwo + 1):
     
            ans += cmb (N - j , j )
     
    ans = ans % 1000000007
    print (ans)

Buggy submission (verdict: Runtime Error):
import math
def cmb(n, r):
    return math.factorial(n)// ( math.factorial(n-r) * math.factorial(r) )



N,M = input().split()

N = int(N)
M = int(M)

a = []
ans = 1

for i in range(M):
    newa = int(input())
    a.append(newa)


for k in range(M-1):
    if (a[k+1] - a[k] == 1):
        ans = 0
            
    
    
for i in range(M + 1):
    

    if (i == 0):
        dan = a[i] - 1
    elif (i == M):
        dan = N - a[i - 1] - 1
    else:
        dan = a[i] - a[i - 1] - 2

    abletwo = (dan - (dan % 2)) // 2
    now = 0

    if (dan != 0):

        for j in range(abletwo + 1):

            now += cmb (dan - j , j )

    else:
        now = 1
        
    ans *= now
    

ans = ans % 1000000007
print (ans)

Buggy submission (verdict: Runtime Error):
import math
def cmb(n, r):
    return math.factorial(n)// ( math.factorial(n-r) * math.factorial(r) )



N,M = input().split()

N = int(N)
M = int(M)

a = []
ans = 1

for i in range(M):
    newa = int(input())
    a.append(newa)


for k in range(M-1):
    if (a[k+1] - a[k] == 1):
        ans = 0
            
    
    
for i in range(M + 1):
    

    if (i == 0):
        dan = a[i] - 1
    elif (i == M):
        dan = N - a[i - 1] - 1
    else:
        dan = a[i] - a[i - 1] - 2

    abletwo = (dan - (dan % 2)) // 2
    now = 0

    for j in range(abletwo + 1):

        now += cmb (dan - j , j )
        
    ans *= now
    

ans = ans % 1000000007
print (ans)

Buggy submission (verdict: Runtime Error):
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result




N,M = input().split()

N = int(N)
M = int(M)

a = []
ans = 1

for i in range(M):
    newa = int(input())
    a.append(newa)


for k in range(M-1):
    if (a[k+1] - a[k] == 1):
        ans = 0
            
    
    
for i in range(M + 1):
    

    if (i == 0):
        dan = a[i] - 1
    elif (i == M):
        dan = N - a[i - 1] - 1
    else:
        dan = a[i] - a[i - 1] - 2

    abletwo = (dan - (dan % 2)) // 2
    now = 0

    for j in range(abletwo + 1):

        now += cmb (dan - j , j )
        #print (dan,"dan j",j,cmb (dan - j , j ))

    ans *= now
    #print (now)

ans = ans % 1000000007
print (ans)