Problem:


会津山スキー場の新企画

 会津山スキー場の経営者である油木屋さんは、上級者向けとして障害物やジャンプ台を配置したコースを用意しました。コースにはいろいろな滑り方があり、シーズン中に全てのパターンの滑り方が出来た利用者には、プレゼントを贈ることになっています。

油木屋さんのために、コースの見取り図をもとに滑り方のパターン数を出力するプログラムを作ってあげましょう。

  コースは上図のような X &times; Y 個のマスからなるグリッドで表されます。左上を原点とし、x 座標は右に行くにつれて大きくなり、y 座標は下にいくにつれて大きくなるものとします。

 各滑り方のパターンは、最も高いところ(y = 1 、ただし障害物の無いところ) からスタートし、ゴール(y = Y) に向かって進んでいきます。グリッドのマス(x, y) にいる滑走者は、(x &minus; 1, y + 1)、(x, y + 1)、 (x + 1, y + 1) のいずれかに移動することができます。マスには、障害物やジャンプ台があり、障害物のあるマスには進入できず、ジャンプ台があるマスに進入すると(x, y + 2) へ移動します。ただし、いちばん高いマス (y = 1 のマス) にはジャンプ台は存在せず、ジャンプ台のあるマスに進入する際には x 座標が同じマスからしか進入できません。コースの上端(y = 1) からスタートし、コースからはずれることなく下端を超えれば(y ≥ Y) 1つの滑り方とみなし、滑り終わります。

  コースの情報を入力とし、滑り方の総数を出力するプログラムを作成してください。

Input

複数のデータセットの並びが入力として与えられます。入力の終わりはゼロふたつの行で示されます。各データセットは以下の形式で与えられます。

X Y
c11 c21 ... cX1
c12 c22 ... cX2
:
c1Y c2Y ... cXY	

1 行目にコースの大きさX, Y (1 ≤ X, Y ≤ 15) が与えられます。続く Y 行にコースの情報が与えられます。cij (0 , 1 , 2 のいずれか) はx = i, y = j のマスの情報を表す整数で、0 が移動可能なマス、1 が障害物があるマス、2 がジャンプ台があるマスを表します。

データセットの数は 50 を超えません。

Output

入力データセットごとに、コースの滑り方のパターン数を1行に出力します。

Sample Input

5 5
0 0 0 0 1
2 1 0 2 0
1 0 0 1 1
0 2 1 2 0
0 1 0 0 0
5 5
0 0 1 0 0
2 1 0 2 0
1 0 0 1 1
0 2 1 2 0
0 1 0 0 0
15 15
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0

Output for the Sample Input

8
6
52694573



Sample input:
5 5
0 0 0 0 1
2 1 0 2 0
1 0 0 1 1
0 2 1 2 0
0 1 0 0 0
5 5
0 0 1 0 0
2 1 0 2 0
1 0 0 1 1
0 2 1 2 0
0 1 0 0 0
15 15
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0


Sample output:
8
6
52694573

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0203

"""
import sys
from sys import stdin
from collections import deque, defaultdict
input = stdin.readline


def solve(field):
    BLANK, OBSTACLE, JUMP = 0, 1, 2
    ans = 0                     #  ??????????????°???????????°

    # dy = [1, 1, 1]
    dx = [0, -1, 1] # ?????????????????????????????????????§???????
    x_limit = len(field[0])
    y_limit = len(field)

    path = defaultdict(int)     #  ??????????????????????????°???????????°????????????'x???_y???'???????????????
    Q = deque()                 #  ?????§??????????????????????????¨??????????????\???

    # ???????????§??????????????§????????´????????¢???????????\??????????????????
    for x, m in enumerate(field[0]):
        if m == BLANK:              #  ?????????????????°?????´?????????????????????????????????
            k = '{}_{}'.format(x, 0)
            Q.append((x, 0))
            path[k] = 1

    while Q:
        cx, cy = Q.popleft()        #  ?????¨??°?????§?¨?
        k = '{}_{}'.format(cx, cy)
        num = path.pop(k)       #  ????????§?¨?????????????????????°

        if field[cy][cx] == OBSTACLE: #  ?????£????????§?????°??????????????????????????±????????????????????????????????§?????£?????????????????
            continue
        elif field[cy][cx] == JUMP: #  ?????£????????§?????°?????????????????£????????°
            if cy+2 > y_limit-1: #  ?????£???????????????????¶?????????´??????OK??¨?????????
                ans += num
            else:
                k = '{}_{}'.format(cx, cy+2)
                if not path[k]:
                    Q.append((cx, cy+2))
                path[k] += num
            continue
        elif cy == y_limit -1:
            ans += num
            continue

        for i in range(3):      #  ?????????3???len(dy)?????????
            nx = cx + dx[i]     #  ?????°????????§?¨?
            ny = cy + 1         #  ??????+1????????§???dy[i]??¨?????????????????????OK

            if 0<= nx < x_limit:
                if field[ny][nx] == JUMP and dx[i] == 0: #  ?????£????????°????????£??????????????\????????´???
                    if ny+2 > y_limit - 1:
                        ans += num
                    else:
                        k = '{}_{}'.format(nx, ny+2)
                        if not path[k]:
                            Q.append((nx, ny+2))
                        path[k] += num
                elif field[ny][nx] == BLANK:
                    if (ny >= y_limit - 1):
                        ans += num
                    else:
                        k = '{}_{}'.format(nx, ny)
                        if not path[k]:
                            Q.append((nx, ny))
                        path[k] += num
    return ans


def solve2(field):
    BLANK, OBSTACLE, JUMP = 0, 1, 2
    ans = 0                     #  ??????????????°???????????°

    dy = [1, 1, 1]  # ?????????????????????????????????????§???????
    dx = [0, -1, 1]
    x_limit = len(field[0])
    y_limit = len(field)

    path = defaultdict(int)     #  ??????????????????????????°???????????°????????????'x???_y???'???????????????
    Q = deque()
    for x, m in enumerate(field[0]):
        if m == BLANK:              #  ?????????????????°?????´?????????????????????????????????
            t = '{}_{}'.format(x, 0)
            Q.append((x, 0))
            path[t] = 1

    while Q:
        cx, cy = Q.popleft()        #  ?????¨??°?????§?¨?
        t = '{}_{}'.format(cx, cy)
        num = path.pop(t)

        if field[cy][cx] == OBSTACLE:
            continue
        elif field[cy][cx] == JUMP: #  ?????£????????§?????°?????????????????£????????°
            if cy+2 > y_limit-1:
                ans += num
            else:
                t = '{}_{}'.format(cx, cy+2)
                if not path[t]:
                    Q.append((cx, cy+2))
                path[t] += num
            continue
        elif cy == y_limit -1:
            ans += num
            continue

        for i in range(3):      #  ?????????3???len(dy)?????????
            nx = cx + dx[i]     #  ?????°????????§?¨?
            ny = cy + dy[i]

            if 0<= nx < x_limit:
                if field[ny][nx] == JUMP and dx[i] == 0: #  ?????£????????°????????£??????????????\????????´???
                    if ny+2 > y_limit - 1:
                        ans += num
                    else:
                        t = '{}_{}'.format(nx, ny+2)
                        if not path[t]:
                            Q.append((nx, ny+2))
                        path[t] += num
                elif field[ny][nx] == BLANK:
                    if (ny >= y_limit - 1):
                        ans += num
                    else:
                        t = '{}_{}'.format(nx, ny)
                        if not path[t]:
                            Q.append((nx, ny))
                        path[t] += num
    return ans


def solve3(field):
    BLANK, OBSTACLE, JUMP = 0, 1, 2
    X = len(field[0])
    Y = len(field)
    dp = [[0] * X for _ in range(Y)]

    # ??????????????°????????????
    for x in range(X):
        if field[0][x] == BLANK:
            dp[0][x] = 1

    for y in range(1, Y):
        for x in range(X):
            t = 0
            mark = field[y][x]
            if mark == BLANK:
                if field[y-1][x] != JUMP:
                    t += dp[y-1][x]
                if x > 0 and field[y-1][x-1] != JUMP:
                    t += dp[y-1][x-1]
                if x < X-1 and field[y-1][x+1] != JUMP:
                    t += dp[y-1][x+1]
                if y > 1 and field[y-2][x] == JUMP:
                    t += dp[y-2][x]
            elif mark == JUMP:
                if field[y-1][x] != JUMP:
                    t = dp[y-1][x]
                if y > 1 and field[y-2][x] == JUMP:
                    t += dp[y-2][x]
            dp[y][x] = t
    ans = sum(dp[-1])
    if Y > 1:
        for x in range(X):
            if field[-2][x] == JUMP:
                ans += dp[-2][x]
    return ans


def main(args):
    while True:
        X, Y = map(int, input().strip().split())
        if X == 0 and Y == 0:
            break
        field = []
        for _ in range(Y):
            temp = [int(x) for x in input().strip().split()]
            field.append(temp)
        result = solve3(field)
        print(result)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

Solution code:
while True:
  x, y = map(int, input().split())
  if x == 0:
    break
  mp = [[1] + list(map(int, input().split())) + [1] for _ in range(y)]
  mp.insert(0, [1] * (x + 2))
  mp.append([0] * (x + 2))
  mp.append([0] * (x + 2))
  tr = [[0] * (x + 2) for _ in range(y + 2)]
  
  for i in range(1, x + 1):
    if mp[1][i] == 0:
      tr[1][i] = 1
  
  for i in range(2, y + 1):
    for j in range(1, x + 1):
      if mp[i][j] == 0:
        for k in range(j - 1, j + 2):
          if mp[i - 1][k] == 0:
            tr[i][j] += tr[i - 1][k]
        if mp[i - 2][j] == 2:
          tr[i][j] += tr[i - 2][j]
  
      elif mp[i][j] == 2:
        if mp[i - 1][j] == 0:
          tr[i][j] += tr[i - 1][j]
        if mp[i - 2][j] == 2:
          tr[i][j] += tr[i - 2][j]
  
  ans = sum(tr[y])
  for i in range(1, x + 1):
    if mp[y - 1][i] == 2:
      ans += tr[y - 1][i]
  print(ans)

Submission status: Accepted

Solution code:
while True:
    X,Y=map(int,raw_input().split())
    if X==Y==0:break
    C=[[0]+map(int,raw_input().split())+[0] for i in range(Y)]
    C.append([0]*(X+2))
    dp=[[0]*(X+2) for i in range(Y+1)]
    for i in range(1,X+1):
        if C[0][i]!=1:
            dp[0][i]=1
    for i in range(Y-1):
        for j in range(1,X+1):
            if C[i][j]==0:
                if C[i+1][j]!=1:
                    dp[i+1][j]+=dp[i][j]
                if C[i+1][j+1]!=1 and C[i+1][j+1]!=2:
                    dp[i+1][j+1]+=dp[i][j]
                if C[i+1][j-1]!=1 and C[i+1][j-1]!=2:
                    dp[i+1][j-1]+=dp[i][j]
            if C[i][j]==2 and C[i+2][j]!=1:
                dp[i+2][j]+=dp[i][j]
    print sum(dp[-1][1:-1])+sum(dp[-2][1:-1])

Submission status: Accepted

Solution code:
while 1:
	X,Y = map(int,raw_input().split())
	if X == 0: break
	A = [[0]+map(int,raw_input().split())+[0] for i in range(Y)]
	S = [[0]*(X+2) for i in range(Y)]
	for x in range(1,X+1): S[0][x] = 1 if A[0][x] == 0 else 0
	for y in range(1,Y):
		for x in range(1,X+1):
			if A[y][x] == 0:
				for i in range(-1,2):
					S[y][x] += S[y-1][x-i] if A[y-1][x-i] == 0 else 0
			if A[y][x] == 2:
				S[y][x] += S[y-1][x] if A[y-1][x] == 0 else 0
				if y+2 < Y and A[y+2][x] != 1:
					S[y+2][x] = S[y][x]
	ans = 0
	for x in range(1,X+1):
		ans += S[Y-1][x] + (S[Y-2][x] if A[Y-2][x] == 2 else 0)
	print ans

Submission status: Accepted

Solution code:
while 1:
    x,y = list(map(int, input().split()))
    if x == 0: break
    c = [list(map(int, input().split())) for _ in range(y)]
    c.append([0]*x)
    c.append([0]*x)
    dp = [[0]*x for _ in range(y+2)]
    for i in range(x):
        if c[0][i] == 0: dp[0][i] = 1
    for i in range(y):
        for j in range(x):
            if c[i][j] == 0:
                if i != y-1:
                    if j != 0 and c[i+1][j-1] == 0:
                        dp[i+1][j-1] += dp[i][j]
                    if j != x-1 and c[i+1][j+1] == 0:
                        dp[i+1][j+1] += dp[i][j]
                    if c[i+1][j] != 1:
                        dp[i+1][j] += dp[i][j]
            elif c[i][j] == 2:
                if c[i+2][j] != 1:
                    dp[i+2][j] += dp[i][j]
    ans = 0
    for i in dp[y-1:y+1]:
        ans += sum(i)
    print(ans)
"""
while 1:
    x,y = list(map(int, input().split()))
    if x == 0: break
    c = [list(map(int, input().split())) for _ in range(y)]
    dp = [[0]*x for _ in range(y+1)]
    for i in range(x):
        if c[0][i] == 0: dp[0][i] = 1
    for i in range(1,y):
        for j in range(x):
            if c[i][j] == 0:
                if i >= 2 and c[i-2][j] == 2:
                    dp[i][j] += dp[i-2][j]
                if j != 0   and c[i-1][j-1] == 0:dp[i][j] += dp[i-1][j-1]
                if j != x-1 and c[i-1][j+1] == 0:dp[i][j] += dp[i-1][j+1]
                if c[i-1][j] != 1: dp[i][j] += dp[i-1][j]
            elif c[i][j] == 2:
                dp[i][j] += dp[i-1][j]
                if i >= 2 and c[i-2][j] == 2:
                    dp[i][j] += dp[i-2][j]
    for i in dp:
        print(i)
    ans = 0
    for i in range(x):
        ans += dp[y-1][i]
        if y >= 2 and c[y-2][i] == 2:
            ans += dp[y-2][j]
    print(ans)
"""

Submission status: Accepted

Solution code:
def printF(field,w,h):
    for i in range(h):
        print(field[i])

def getp(f,p,y,x,h,w,v):
    if y<0 or x<0 or x>=w:
        return 0
    if y>=h:
        if v==True:
            return 1
        return 0

    
    k = f[y][x]
    r = 0
    if k==0:
        if p[y][x]>=0:
            return p[y][x]

        r = getp(f,p,y+1,x-1,h,w,False)+getp(f,p,y+1,x,h,w,True)+getp(f,p,y+1,x+1,h,w,False)
        p[y][x] = r
    elif k==1:
        r = 0
    elif k==2:
        if v == True:
            if p[y][x]>=0:
                return p[y][x]
            r = getp(f,p,y+2,x,h,w,True)
            p[y][x] = r
        else:
            r = 0

    #print("gp({},{},{}):({},{})".format(x,y,v,k,r))
    return r

w,h = map(int,input().split())
while w!=0 and h != 0:
    field = []

    for i in range(h):
        field.append(list(map(int,input().split())))
        

    #initialize
    p = []
    for i in range(h):
        p.append([-1]*w)

    #calc

    print(sum(map(lambda x:getp(field,p,0,x,h,w,True), range(w))))

    w,h = map(int,input().split())

Submission status: Accepted

Solution code:
while True:
    X, Y = map(int, input().split())
    if X == 0:
        break
    a = [[1]+list(map(int, input().split()))+[1] for _ in [0]*Y] + [[0]*(X+2)]
    dp = [list(map(lambda x: x^1, a[0]))] + [[0]*(X+2) for _ in [0]*Y]

    for y in range(Y-1):
        for x, (square, cnt) in enumerate(zip(a[y][1:], dp[y][1:-1]), start=1):
            if square == 0:
                for tx in range(x-1, x+2):
                    if a[y+1][tx] == 0 or a[y+1][tx] == 2 and x == tx:
                        dp[y+1][tx] += cnt
            elif square == 2:
                dp[y+2][x] += cnt
    for x in range(1, X+1):
        if a[Y-1][x] != 1:
            dp[Y][x] += dp[Y-1][x]

    print(sum(dp[-1]))

Submission status: Accepted

Solution code:
while(True):
    X,Y = map(int, input().split())
    if X==0 and Y==0:
        break
    ar = [list(map(int, input().split())) for _ in range(Y)]
    ar.append([0]*X)
    br = [[0]*X for _ in range(Y+1)]
    for j in range(X):
        if ar[-2][j] != 1:
            br[-2][j] = 1
        br[-1][j] = 1
    for i in range(Y-2,-1,-1):
        for j in range(X):
            if j-1 >= 0 and ar[i][j] != 2 and ar[i+1][j-1] == 0: br[i][j] += br[i+1][j-1]
            if j+1 < X and ar[i][j] != 2 and ar[i+1][j+1] == 0: br[i][j] += br[i+1][j+1]
            if ar[i][j] != 2 and ar[i+1][j] != 1: br[i][j] += br[i+1][j]
            if ar[i][j] == 2 and ar[i+2][j] != 1: br[i][j] += br[i+2][j]
        for j in range(X):
            if ar[i][j] == 1: br[i][j] = 0
    print(sum(br[0]))

Submission status: Runtime Error

Solution code:
while(1):
    [X,Y]=[int(x) for x in raw_input().split()]
    if X==0:
        break
    else:
        F=[]
        for i in range(Y):
            F.append([0]+[int(x) for x in raw_input().split()]+[0])
        F.append([3 for x in range(X+2)])
        S=[[0 for x in range(X+2)] for y in range(Y+1)] #F,S[y][x]
        
        #initilizing
        for i in range(1,X+1):
            S[0][i]=1-F[0][i]
        for j in range(Y+1):
            for i in range(1,X+1):
                if F[j][i]==2:
                    S[j][i]=S[j][i]+S[j-1][i]
                    S[j+2][i]=S[j+2][i]+S[j][i]
                elif F[j][i]==1:
                    S[j][i]=0
                elif F[j][i]==3:
                    S[j][i]=S[j][i]+S[j-1][i]
                else:
                    S[j][i]=S[j][i]+(1-F[j-1][i]/2)*S[j-1][i]+(1-F[j-1][i-1]/2)*S[j-1][i-1]+(1-F[j-1][i+1]/2)*S[j-1][i+1]
        print sum(S[Y])

Submission status: Runtime Error

Solution code:
""" Created by Jieyi on 8/16/16. """


def algorithm():
    def down_jump(x, y, times):
        if x == r:
            out_map[x - 1][y] += times
        elif in_map[x][y] == 2:
            down_jump(x + 2, y, times)
        else:
            out_map[x][y] += times

    while True:
        c, r = map(int, input().split())
        if c == 0 and r == 0:
            break

        in_map = []
        out_map = [[0 for _ in range(c)] for _ in range(r)]
        for _ in range(r):
            in_map.append(list(map(int, input().split())))

        for i in range(r):
            if in_map[0][i] == 0:
                out_map[0][i] = 1

        for i in range(r):
            for j in range(c):
                if in_map[i][j] == 0:
                    # ???.
                    if i + 1 < r and j > 0 and in_map[i + 1][j - 1] == 0:
                        out_map[i + 1][j - 1] += out_map[i][j]
                    # ???.
                    if i + 1 < r and in_map[i + 1][j] == 0:
                        out_map[i + 1][j] += out_map[i][j]
                    elif i + 1 < r and in_map[i + 1][j] == 2:
                        down_jump(i + 1, j, out_map[i][j])
                    # ???.
                    if i + 1 < r and j + 1 < c and in_map[i + 1][j + 1] == 0:
                        out_map[i + 1][j + 1] += out_map[i][j]

        print(sum(out_map[c - 1]))


def main():
    algorithm()


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
""" Created by Jieyi on 8/16/16. """


def algorithm():
    def down_jump(x, y, times):
        if x == r:
            out_map[x - 1][y] += times
        elif x == r - 1:
            out_map[x][y] += times
        elif in_map[x][y] == 2:
            down_jump(x + 2, y, times)
        else:
            out_map[x][y] += times

    while True:
        c, r = map(int, input().split())
        if c == 0 and r == 0:
            break

        in_map = []
        out_map = [[0 for _ in range(c)] for _ in range(r)]
        for _ in range(r):
            in_map.append(list(map(int, input().split())))

        for i in range(r):
            if in_map[0][i] == 0:
                out_map[0][i] = 1

        for i in range(r):
            for j in range(c):
                if in_map[i][j] == 0:
                    # ???.
                    if i + 1 < r and j > 0 and in_map[i + 1][j - 1] == 0:
                        out_map[i + 1][j - 1] += out_map[i][j]
                    # ???.
                    if i + 1 < r and in_map[i + 1][j] == 0:
                        out_map[i + 1][j] += out_map[i][j]
                    elif i + 1 < r and in_map[i + 1][j] == 2:
                        down_jump(i + 1, j, out_map[i][j])
                    # ???.
                    if i + 1 < r and j + 1 < c and in_map[i + 1][j + 1] == 0:
                        out_map[i + 1][j + 1] += out_map[i][j]

        print(sum(out_map[c - 1]))


def main():
    algorithm()


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
""" Created by Jieyi on 8/16/16. """


def algorithm():
    def down_jump(x, y, times):
        if x == r:
            out_map[x - 1][y] += times
        elif x == r - 1:
            out_map[x][y] += times
        elif in_map[x][y] == 2:
            down_jump(x + 2, y, times)
        else:
            out_map[x][y] += times

    while True:
        c, r = map(int, input().split())
        if c == 0 and r == 0:
            break

        in_map = []
        out_map = [[0 for _ in range(c)] for _ in range(r)]
        for _ in range(r):
            in_map.append(list(map(int, input().split())))

        for i in range(c):
            if in_map[0][i] == 0 or in_map[0][i] == 2:
                out_map[0][i] = 1

        for i in range(r):
            for j in range(c):
                if in_map[i][j] == 0:
                    # ???.
                    if i + 1 < r and j > 0 and in_map[i + 1][j - 1] == 0:
                        out_map[i + 1][j - 1] += out_map[i][j]
                    # ???.
                    if i + 1 < r and in_map[i + 1][j] == 0:
                        out_map[i + 1][j] += out_map[i][j]
                    elif i + 1 < r and in_map[i + 1][j] == 2:
                        down_jump(i + 1, j, out_map[i][j])
                    # ???.
                    if i + 1 < r and j + 1 < c and in_map[i + 1][j + 1] == 0:
                        out_map[i + 1][j + 1] += out_map[i][j]

        print(out_map)
        print(sum(out_map[c - 1]))


def main():
    algorithm()


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0203

"""
import sys
from sys import stdin
from collections import deque, defaultdict
input = stdin.readline


def solve(field):
0 0    # 0: ????????°, 1: ?????????, 2: ?????£????????°
    course = 0

    # ??????????????????????????????
    dy = [1, 1, 1]
    dx = [0, -1, 1]
    x_limit = len(field[0])
    y_limit = len(field)

    path = defaultdict(int)
    Q = deque()
    for x, m in enumerate(field[0]):
        if m == 0:
            Q.append((x, 0))
            t = '{}_{}'.format(x, 0)
            path[t] = 1

    while Q:
        cx, cy = Q.popleft()        #  ?????¨??°?????§?¨?
        t = '{}_{}'.format(cx, cy)
        num = path.pop(t)
        if cy+1 == y_limit:
            course += num
            continue
        if field[cy][cx] == 2:
            if cy+2 >= y_limit:
                course += num
            else:
                t = '{}_{}'.format(cx, cy)
                if path[t]:
                    path[t] += num
                else:
                    Q.append((cx, cy+2))
                    path[t] = num
            continue
        for i in range(len(dx)):
            nx = cx + dx[i]
            ny = cy + dy[i]
            #  ?§????????????§???????????? ?????? ??¢?????¢?´¢?????§???????????°??????????????§?????¢?´¢????¶???????
            if 0<= nx < x_limit:
                if ny >= y_limit:
                    course += num
                else:
                    if field[ny][nx] == 2 and dx[i] == 0:
                        if ny+2 >= y_limit:
                            course += num
                        else:
                            t = '{}_{}'.format(nx, ny+2)
                            if path[t]:
                                path[t] += num
                            else:
                                path[t] = num
                                Q.append((nx, ny+2))
                    elif field[ny][nx] == 0:
                        t = '{}_{}'.format(nx, ny)
                        if path[t]:
                            path[t] += num
                        else:
                            path[t] = num
                            Q.append((nx, ny))
    return course



def main(args):
    while True:
        X, Y = map(int, input().split())
        if X == 0 and Y == 0:
            break
        field = []
        for _ in range(Y):
            temp = [int(x) for x in input().split()]
            field.append(temp)
        result = solve(field)
        print(result)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0203

"""
import sys
from sys import stdin
from collections import deque, defaultdict
input = stdin.readline


def solve(field):
    # 0: ????????°, 1: ?????????, 2: ?????£????????°
    course = 0

    # ??????????????????????????????
    dy = [1, 1, 1]
    dx = [0, -1, 1]
    x_limit = len(field[0])
    y_limit = len(field)

    path = defaultdict(int)     #  ??????????????????????????°???????????°
    Q = deque()
    for x, m in enumerate(field[0]):
        if m == 0:
            Q.append((x, 0))
            t = '{}_{}'.format(x, 0)
            path[t] = 1

    while Q:
        cx, cy = Q.popleft()        #  ?????¨??°?????§?¨?
        t = '{}_{}'.format(cx, cy)
        num = path.pop(t)

        if field[cy][cx] == 2:
            if cy+2 >= y_limit-1:
                course += num
            else:
                t = '{}_{}'.format(cx, cy)
                if path[t]:
                    path[t] += num
                else:
                    Q.append((cx, cy+2))
                    path[t] = num
            continue


        for i in range(len(dx)):
            nx = cx + dx[i]
            ny = cy + dy[i]
            #  ?§????????????§???????????? ?????? ??¢?????¢?´¢?????§???????????°??????????????§?????¢?´¢????¶???????
            if 0<= nx < x_limit:
                if ny >= y_limit - 1 and field[ny][nx] != 1:
                    course += num
                else:
                    if field[ny][nx] == 2 and dx[i] == 0:
                        if ny+2 >= y_limit - 1:
                            course += num
                        else:
                            t = '{}_{}'.format(nx, ny+2)
                            if path[t]:
                                path[t] += num
                            else:
                                path[t] = num
                                Q.append((nx, ny+2))
                    elif field[ny][nx] == 0:
                        t = '{}_{}'.format(nx, ny)
                        if path[t]:
                            path[t] += num
                        else:
                            path[t] = num
                            Q.append((nx, ny))
    return course



def main(args):
    while True:
        X, Y = map(int, input().split())
        if X == 0 and Y == 0:
            break
        field = []
        for _ in range(Y):
            temp = [int(x) for x in input().split()]
            field.append(temp)
        result = solve(field)
        print(result)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0203

"""
import sys
from sys import stdin
from collections import deque, defaultdict
input = stdin.readline


def solve(field):
    # 0: ????????°, 1: ?????????, 2: ?????£????????°
    course = 0

    # ??????????????????????????????
    dy = [1, 1, 1]
    dx = [0, -1, 1]
    x_limit = len(field[0])
    y_limit = len(field)

    path = defaultdict(int)     #  ??????????????????????????°???????????°
    Q = deque()
    for x, m in enumerate(field[0]):
        if m == 0:
            Q.append((x, 0))
            t = '{}_{}'.format(x, 0)
            path[t] = 1
    if x_limit == 1:
        return len(Q)

    while Q:
        cx, cy = Q.popleft()        #  ?????¨??°?????§?¨?
        t = '{}_{}'.format(cx, cy)
        num = path.pop(t)

        if field[cy][cx] == 2:
            if cy+2 >= y_limit-1:
                course += num
            else:
                t = '{}_{}'.format(cx, cy)
                if path[t]:
                    path[t] += num
                else:
                    Q.append((cx, cy+2))
                    path[t] = num
            continue


        for i in range(len(dx)):
            nx = cx + dx[i]
            ny = cy + dy[i]
            #  ?§????????????§???????????? ?????? ??¢?????¢?´¢?????§???????????°??????????????§?????¢?´¢????¶???????
            if 0<= nx < x_limit:
                if ny >= y_limit - 1 and field[ny][nx] != 1:
                    course += num
                else:
                    if field[ny][nx] == 2 and dx[i] == 0:
                        if ny+2 >= y_limit - 1:
                            course += num
                        else:
                            t = '{}_{}'.format(nx, ny+2)
                            if path[t]:
                                path[t] += num
                            else:
                                path[t] = num
                                Q.append((nx, ny+2))
                    elif field[ny][nx] == 0:
                        t = '{}_{}'.format(nx, ny)
                        if path[t]:
                            path[t] += num
                        else:
                            path[t] = num
                            Q.append((nx, ny))
    return course



def main(args):
    while True:
        X, Y = map(int, input().split())
        if X == 0 and Y == 0:
            break
        field = []
        for _ in range(Y):
            temp = [int(x) for x in input().split()]
            field.append(temp)
        result = solve(field)
        print(result)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0203

"""
import sys
from sys import stdin
from collections import deque, defaultdict
input = stdin.readline


def solve(field):
    # 0: ????????°, 1: ?????????, 2: ?????£????????°
    ans = 0

    # ??????????????????????????????
    dy = [1, 1, 1]
    dx = [0, -1, 1]
    x_limit = len(field[0])
    y_limit = len(field)

    path = defaultdict(int)     #  ??????????????????????????°???????????°
    Q = deque()
    for x, m in enumerate(field[0]):
        if m == 0:
            Q.append((x, 0))
            t = '{}_{}'.format(x, 0)
            path[t] = 1
    if x_limit == 1:
        return len(Q)

    while Q:
        cx, cy = Q.popleft()        #  ?????¨??°?????§?¨?
        t = '{}_{}'.format(cx, cy)
        num = path.pop(t)

        if field[cy][cx] == 2:
            if cy+2 >= y_limit-1:
                ans += num
            else:
                t = '{}_{}'.format(cx, cy)
                if path[t]:
                    path[t] += num
                else:
                    Q.append((cx, cy+2))
                    path[t] = num
            continue


        for i in range(len(dx)):
            nx = cx + dx[i]
            ny = cy + dy[i]
            #  ?§????????????§???????????? ?????? ??¢?????¢?´¢?????§???????????°??????????????§?????¢?´¢????¶???????
            if 0<= nx < x_limit:
                if ny >= y_limit - 1 and field[ny][nx] != 1:
                    ans += num
                else:
                    if field[ny][nx] == 2 and dx[i] == 0:
                        if ny+2 >= y_limit - 1:
                            ans += num
                        else:
                            t = '{}_{}'.format(nx, ny+2)
                            if path[t]:
                                path[t] += num
                            else:
                                path[t] = num
                                Q.append((nx, ny+2))
                    elif field[ny][nx] == 0:
                        t = '{}_{}'.format(nx, ny)
                        if path[t]:
                            path[t] += num
                        else:
                            path[t] = num
                            Q.append((nx, ny))
    return ans


def main(args):
    while True:
        X, Y = map(int, input().strip().split())
        if X == 0 and Y == 0:
            break
        field = []
        for _ in range(Y):
            temp = [int(x) for x in input().strip().split()]
            field.append(temp)
        result = solve(field)
        print(result)


if __name__ == '__main__':
    main(sys.argv[1:])