Problem p03013 (python)

Fixed submission:
N, M = [int(nm) for nm in input().split()]
if M != 0:
  a = int(input())

C = [1, 0] # [-2段目, -1段目]
C += [0]*(N+10) # C = [-2段目, -1段目, 0段目, 1段目, 2段目, ...]
for n in range(0, N+1):
  if M == 0:
    C[n+2] = (C[n] + C[n+1]) % 1000000007
  else: # M > 0:
    if n != a:
      C[n+2] = (C[n] + C[n+1]) % 1000000007
    else: # n == a:
      C[n+2] = 0
      M -= 1
      if M > 0:
        a = int(input())

ans = C[N+2]  % 1000000007
print(ans)

Buggy submission (verdict: Runtime Error):
N, M = [int(nm) for nm in input().split()]
if M != 0:
  a = int(input())
  M -= 1

C = [1, 0] # [-2段目, -1段目]
C += [0]*(N+10) # C = [-2段目, -1段目, 0段目, 1段目, 2段目, ...]
for n in range(0, N+1):
  if n != a or M == 0:
    C[n+2] = (C[n] + C[n+1]) % 1000000007
  else: # n == a and M != 0:
    C[n+2] = 0
    a = int(input())
    M -= 1

ans = C[N+2]  % 1000000007
print(ans)

Buggy submission (verdict: Runtime Error):
N, M = [int(nm) for nm in input().split()]
A = []
for m in range(M):
  A.append(int(input()))

for n in range(N+1):
  if n == 0:
    i1 = 1
  elif n == 1:
    i2 = 1
    if n in A:
      i2 = 0
  else:
    i3 = i1 + i2
    if n in A:
      i3 = 0
    i1, i2 = i2, i3

ans = i3 % (10**9 + 7)
print(ans)

Buggy submission (verdict: Runtime Error):
N, M = [int(nm) for nm in input().split()]
A = []
for m in range(M):
  A.append(int(input()))

for n in range(N, -1, -1):
  if n == N:
    i2 = 1
  elif n == N-1:
    i1 = 1
    if n in A:
      i1 = 0
  else:
    i = i1 + i2
    if n in A:
      i = 0
    i1, i2 = i, i1

ans = i % (10**9 + 7)
print(ans)

Buggy submission (verdict: Runtime Error):
N, M = [int(nm) for nm in input().split()]
A = [-1]
for m in range(M):
  A.append(int(input()))
A.append(N+1)

import math
total_case = 1
for m in range(M+1):
  a1 = A[m]
  a2 = A[m+1]
  safe_stairs = a2 - a1 - 1
  if safe_stairs == 0:
    print(0)
    break
  howmany_jump1 = safe_stairs - 1
  mx_jump2 = howmany_jump1 // 2
  #２のジャンプは０回～（mx_jump2）回
  case = 0
  for j2 in range(mx_jump2 + 1):
    jump2 = j2
    jump1 = howmany_jump1 - (j2 * 2)
    c = math.factorial(jump1 + jump2) / (math.factorial(jump1) * math.factorial(jump2))
    case += c
  total_case *= case
else:
  ans = int(total_case % (10**9 + 7))
  print(ans)

Buggy submission (verdict: Runtime Error):
N, M = [int(nm) for nm in input().split()]
A = [-1]
for m in range(M):
  A.append(int(input()))
A.append(N+1)

import math
total_case = 1
for m in range(M+1):
  a1 = A[m]
  a2 = A[m+1]
  safe_stairs = a2 - a1 - 1
  howmany_jump1 = safe_stairs - 1
  mx_jump2 = howmany_jump1 // 2
  #２のジャンプは０回～（mx_jump2）回
  case = 0
  for j2 in range(mx_jump2 + 1):
    jump2 = j2
    jump1 = howmany_jump1 - (j2 * 2)
    c = math.factorial(jump1 + jump2) / (math.factorial(jump1) * math.factorial(jump2))
    case += c
  total_case *= case

ans = int(total_case % (10**9 + 7))
print(ans)

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

import math
a_1 = -1
nm_of_cs = 1
for m in range(M+1):
  a_0 = a_1
  if m < M:
    a_1 = int(input())
  else:
    a_1 = N+1
  if a_0 + 1 == a_1:
    nm_of_cs = 0
    break
  d_01 = (a_1 - 1) - (a_0 + 1)
  if d_01 % 2 == 0:
    nm_of_cs *= 2**(d_01 // 2)
  else :
    cs = 0
    for i in range(d_01//2 + 1):
      cs += math.factorial(d_01-i)/(math.factorial(i) + math.factorial(d_01-i*2))
    nm_of_cs *= cs

ans = nm_of_cs % 1000000007
print(ans)