Problem p03013 (python)

Fixed submission:



mod=10**9+7
n,m=list(map(int,input().split()))
a=[int(input()) for _ in range(m)]
fib=[1,1]
c=0
if m>0 and a[0]==1:
    fib[1]=0
    c+=1
for i in range(2,n+1):
    if c<m and a[c]==i:
        fib.append(0)
        c+=1
    else:
        fib.append((fib[i-2]+fib[i-1])%mod)

print(fib[n])

Buggy submission (verdict: Runtime Error):
from math import factorial
N,M=list(map(int,input().split()))

ans=1
flag=True
if M>0:
    dansa=[int(input()) for _ in range(M)]
    if dansa[0]==0:
        print("0")
    else:
        if len(dansa)>1:
            for i in range(M-1):
                if dansa[i]+1==dansa[i+1]:
                    print("0")
                    flag=False
                    break
    if flag:
        dansa.insert(0,0)
        dansa.append(N)
        for i in range(M+1):
            tmp=dansa[i+1]-dansa[i]-1
            arr=[i for i in range(int(tmp/2)+1)]
            #print("tmp:{}".format(tmp))
            hoge=0
            """
            if tmp%2==0:
                arr=[j*2 for j in range(0,int(tmp/2+1))]

            else:
                arr=[j*2+1 for j in range(0,int((tmp+1)/2))]
            """
            #print(arr)
            #if tmp%2==0:
            for k in arr:
                n=tmp-k
                hoge+=factorial(n) / factorial(k) / factorial(n-k)

            #print(hoge)
            ans=ans*hoge
            #print(ans)
        print(int(ans%1000000007))
        #print(ans)
else:
    tmp=N
    arr=[i for i in range(int(tmp/2)+1)]
    hoge=0
    for k in arr:
                n=tmp-k
                hoge+=factorial(n) / factorial(k) / factorial(n-k)
    ans=hoge
    print(ans)

Buggy submission (verdict: Runtime Error):
from math import factorial
N,M=list(map(int,input().split()))
dansa=[int(input()) for _ in range(M)]
ans=1
flag=True
if dansa[0]==0:
    print("0")
else:
    if len(dansa)>1:
        for i in range(M-1):
            if dansa[i]+1==dansa[i+1]:
                print("0")
                flag=False
                break
if flag:
    dansa.insert(0,0)
    dansa.append(N)
    for i in range(M+1):
        tmp=dansa[i+1]-dansa[i]-1
        arr=[i for i in range(int(tmp/2)+1)]
        #print("tmp:{}".format(tmp))
        hoge=0
        """
        if tmp%2==0:
            arr=[j*2 for j in range(0,int(tmp/2+1))]
            
        else:
            arr=[j*2+1 for j in range(0,int((tmp+1)/2))]
        """
        #print(arr)
        #if tmp%2==0:
        for k in arr:
            n=tmp-k
            hoge+=factorial(n) / factorial(k) / factorial(n-k)
            
        #print(hoge)
        ans=ans*hoge
        #print(ans)
    print(int(ans%1000000007))
    #print(ans)

Buggy submission (verdict: Runtime Error):
from math import factorial
N,M=list(map(int,input().split()))
dansa=[int(input()) for _ in range(M)]
ans=1
flag=True
if dansa[0]==0:
    print("0")
else:
    if len(dansa)>1:
        for i in range(M-1):
            if dansa[i]+1==dansa[i+1]:
                print("0")
                flag=False
                break
if flag:
    dansa.insert(0,0)
    dansa.append(N)
    for i in range(M+1):
        tmp=dansa[i+1]-dansa[i]-1
        arr=[i for i in range(int(tmp/2)+1)]
        #print("tmp:{}".format(tmp))
        hoge=0
        """
        if tmp%2==0:
            arr=[j*2 for j in range(0,int(tmp/2+1))]
            
        else:
            arr=[j*2+1 for j in range(0,int((tmp+1)/2))]
        """
        #print(arr)
        #if tmp%2==0:
        for k in arr:
            n=tmp-k
            hoge+=factorial(n) / factorial(k) / factorial(n-k)
            
        print(hoge)
        ans=ans*hoge
        print(ans)
    #print(int(ans%1000000007))
    print(ans)