Problem:


アカ・ベコと４０人の盗賊

40 人の盗賊から逃れようとしているアカ・ベコは、A 市の街中で道に迷ってしまった。アカ・ベコは新しいアジトがあるB 市に行きたいのだが地図を盗賊に盗まれてしまった。

盗賊の一人であるコボー氏はアカ・ベコに同情し、気の毒に思っていた。そこで、密かにアカ・ベコに、「あなたがB 市に行くお手伝いをしたいが、仲間にばれない様にしなければならないので、直接道順を教えたいが教えることができない。しかし、あなたの質問には答えられる。」と伝言を送った。

コボー氏は、「○○という道順はどうか。」という質問をアカ・ベコから受け取ると、それがA 市からB市までちょうどたどり付ける道順ならYes、そうでなければNo という答えを伝える。道順のチェックは以下の地図に従って行う。

各都市は一方通行の道でつながっており、それぞれの道には、0 か1 の数字が付いている。アカ・ベコは数字の並びで道順を指定する。例えば、0100 は A 市から X、Z、W 市を経由して B 市にちょうどたどり着く道順である。地図にない道順を選ぶと砂漠に迷い込んでしまい、決して B 市にたどり着くことはない。アカ・ベコは自分がいる都市の名前を知ることはできないため、道順をたどり終えたときにちょうど B 市に到達する必要がある。

コボー氏はアカ・ベコからの質問に答えるために、あなたを密かに雇いプログラムの作成を依頼した。アカ・ベコからの質問を入力すると、それがA 市からB 市にちょうどたどり付ける道順なら Yes、そうでなければ No と出力するプログラムを作成してほしい。

入力

入力は複数のデータセットからなる。入力の終わりは #（シャープ）１つの行で示される。各データセットは以下の形式で与えられる。

p

１行に道順を示す数字 0, 1 の並び p が与えられる。p は100文字を超えない文字列である。

データセットの数は 100 を超えない。

出力

データセットごとに、Yes または No を１行に出力する。

入力例

0100
0101
10100
01000
0101011
0011
011111
#

出力例

Yes
No
Yes
No
Yes
No
Yes

４つ目のデータセットでは、B 市を通りすぎてY 市に到達する道順なので No と出力する。

５つ目のデータセットでは、同じ都市を何度か通っているが、B 市にちょうどたどり着く道順なので Yes と出力する。

６つ目のデータセットでは、X 市から砂漠に迷い込んでしまいB 市にはたどり着けないので No と出力する。

最後のデータセットでは、B 市をいったん通り過ぎてから、X 市とZ 市を経由してB 市にちょうどたどり着く道順なので Yes と出力する。



Sample input:
0100
0101
10100
01000
0101011
0011
011111
#


Sample output:
Yes
No
Yes
No
Yes
No
Yes

Submission status: Wrong Answer

Solution code:
map_ = ( \
        (1,4) # start
        ,(-1,2)
        ,(5,3) 
        ,(4,1) # goal
        ,(1,-1)
        ,(3,4)
        )

while 1:
    x = input()
    if x == '#':break
    
    pt = 0
    for v in map(int,list(x)):
        pt = map_[pt][v]

    print("Yes" if pt == 3 else "No")

Submission status: Wrong Answer

Solution code:
dic={"A":{0:"X",1:"Y"},
     "X":{1:"Z"},
     "Y":{0:"X"},
     "Z":{0:"W",1:"B"},
     "W":{0:"B",1:"Y"},
     "B":{0:"Y",1:"X"}}

while True:
    route=raw_input()
    if route=="#":break
    state="A"
    for r in map(int,route):
        if r not in dic[state]:
            print "NO"
            break
        state=dic[state][r]
    else:
        print "YES" if state=="B" else "NO"

Submission status: Wrong Answer

Solution code:
dic={"A":{0:"X",1:"Y"},
     "X":{1:"Z"},
     "Y":{0:"X"},
     "Z":{0:"W",1:"B"},
     "W":{0:"B",1:"Y"},
     "B":{0:"Y",1:"X"}}

while True:
    route=raw_input()
    if route=="#":break
    state="A"
    flag=True
    for r in map(int,route):
        if r not in dic[state]:
            flag=False
            break
        state=dic[state][r]
    print "YES" if state=="B" and flag else "NO"

Submission status: Wrong Answer

Solution code:
dic={"A":{0:"X",1:"Y"},
     "X":{0:" ",1:"Z"},
     "Y":{0:"X",1:" "},
     "Z":{0:"W",1:"B"},
     "W":{0:"B",1:"Y"},
     "B":{0:"Y",1:"X"}}

while True:
    route=raw_input()
    if route=="#":break
    state="A"
    for r in map(int,route):
        state=dic[state][r]
        if state==" ":
            print "NO"
            break
    else:
        print "YES" if state=="B" else "NO"

Submission status: Wrong Answer

Solution code:
dic={"A":{0:"X",1:"Y"},
     "X":{0:"E",1:"Z"},
     "Y":{0:"X",1:"E"},
     "Z":{0:"W",1:"B"},
     "W":{0:"B",1:"Y"},
     "B":{0:"Y",1:"X"},
     "E":{0:"E",1:"E"}}

while True:
    route=raw_input()
    if route=="#":break
    state="A"
    for r in map(int,route):
        state=dic[state][r]
    print "YES" if state=="B" else "NO"

Submission status: Wrong Answer

Solution code:
dic={"A":{"0":"X","1":"Y"},
     "X":{"0":"E","1":"Z"},
     "Y":{"0":"X","1":"E"},
     "Z":{"0":"W","1":"B"},
     "W":{"0":"B","1":"Y"},
     "B":{"0":"Y","1":"X"},
     "E":{"0":"E","1":"E"}}

while True:
    route=raw_input()
    if route=="#":break
    state="A"
    for r in route:
        state=dic[state][r]
        print state
    print "YES" if state=="B" else "NO"

Submission status: Wrong Answer

Solution code:
dic={"A":{"0":"X","1":"Y"},
     "X":{"0":"E","1":"Z"},
     "Y":{"0":"X","1":"E"},
     "Z":{"0":"W","1":"B"},
     "W":{"0":"B","1":"Y"},
     "B":{"0":"Y","1":"X"},
     "E":{"0":"E","1":"E"}}
"""    state="A"
    for r in route:
        state=dic[state][r]
        print state
    print "YES" if state=="B" else "NO"
"""
while True:
    route=raw_input()
    if route=="#":break
    state="A"
    for i in range(len(route)):
        d=state
        if route[i]=="1":
            if state == 'A':
                state = 'Y'
            elif state == 'W':
                state = 'Y'
            elif state == 'B':
                state = 'X'
            elif state == 'X':
                state = 'Z'
            elif state == 'Z':
                state = 'B'
        elif route[i]=="0":
            if state == 'A':
                state = 'X'
            elif state == 'Y':
                state = 'X'
            elif state == 'Z':
                state = 'W'
            elif state == 'W':
                state = 'B'
            elif state == 'B':
                state = 'Y'
        if d==state:
            state="*"
    if state=="B":
        print "YES"
    else:
        print "NO"

Submission status: Wrong Answer

Solution code:
while True:
    route=raw_input()
    if route=="#":break
    state="A"
    for i in range(len(route)):
        d=state
        if route[i]=="1":
            if state == 'A':
                state = 'Y'
            elif state == 'W':
                state = 'Y'
            elif state == 'B':
                state = 'X'
            elif state == 'X':
                state = 'Z'
            elif state == 'Z':
                state = 'B'
        elif route[i]=="0":
            if state == 'A':
                state = 'X'
            elif state == 'Y':
                state = 'X'
            elif state == 'Z':
                state = 'W'
            elif state == 'W':
                state = 'B'
            elif state == 'B':
                state = 'Y'
        if d==state:
            state="*"
    if state=="B":
        print "YES"
    else:
        print "NO"

Submission status: Accepted

Solution code:
map_ = ( \
        (1,4) # start
        ,(-1,2)
        ,(5,3) 
        ,(4,1) # goal
        ,(1,-1)
        ,(3,4)
        )

while 1:
    x = input()
    if x == '#':break
    
    pt = 0
    for v in map(int,list(x)):
        pt = map_[pt][v]
        if pt == -1: break

    print("Yes" if pt == 3 else "No")

Submission status: Accepted

Solution code:
def go_to(state, digit):
    if state == 'A':
        if digit == '1':
            return 'Y'
        else:
            return 'X'
    elif state == 'X':
        if digit == '1':
            return 'Z'
        else:
            return 'L'
    elif state == 'Y':
        if digit == '1':
            return 'L'
        else:
            return 'X'
    elif state == 'Z':
        if digit == '1':
            return 'B'
        else:
            return 'W'
    elif state == 'W':
        if digit == '1':
            return 'Y'
        else:
            return 'B'
    else:
        if digit == '1':
            return 'X'
        else:
            return 'Y'

while True:
    s = raw_input()
    if s[0] == '#':
        break
    sl = len(s)

    state = 'A'
    for i in range(sl):
        state = go_to(state, s[i])
        if state == 'L': #Lost
            print "No"
            break
    else:
        if state == 'B':
            print 'Yes'
        else:
            print 'No'

Submission status: Accepted

Solution code:
edge = [[-1, 0, 1, -1, -1, -1],\
        [-1, -1, -1, 1, -1, -1],\
        [-1, 0, -1, -1, -1, -1],\
        [-1, -1, -1, -1, 0, 1],\
        [-1, -1, 1, -1, -1, 0],\
        [-1, 1, 0, -1, -1, -1]]

while True:
    s = input()
    if (s == '#'):
        break

    place = 0;
    for i in range(len(s)):
        num = int(s[i])
        if (num not in edge[place]):
            place = -1
            break
        for j in range(6):
            if (edge[place][j] == num):
                place = j
                break

    if (place == 5):
        print('Yes')
    else:
        print('No')

Submission status: Accepted

Solution code:
# Aizu Problem 0266: Aka-beko and 40 Thieves

import sys, math, os, datetime

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


routes = {'A': {'0': 'X', '1': 'Y'},
          'X': {'1': 'Z'},
          'Y': {'0': 'X'},
          'Z': {'0': 'W', '1': 'B'},
          'W': {'0': 'B', '1': 'Y'},
          'B': {'0': 'Y', '1': 'X'}}

def solve(inp):
    cur = 'A'
    k = 0
    while k < len(inp):
        route = inp[k]
        if route in routes[cur]:
            cur = routes[cur][route]
        else:
            return "No"
        k += 1
    return "Yes" if cur == 'B' else "No"


while True:
    inp = input().strip()
    if inp == "#":
        break
    print(solve(inp))

Submission status: Accepted

Solution code:
# AOJ 0266: Aka-beko and 40 Thieves
# Python3 2018.6.26 bal4u

e = ((1, 2), (-1, 3), (1, -3), (4, 5), (5, 2), (2, 1))

while True:
	p = input()
	if p[0] == '#': break
	s, ans = 0, True;
	for i in p:
		s = e[s][int(i)]
		if s < 0:
			ans = False
			break
	if ans and s != 5: ans = False
	print("Yes" if ans else "No")

Submission status: Accepted

Solution code:
edges = [[] for _ in range(7)]
"""
A:0, B:1, X:2, Y:3, Z:4, W:5, NA:61
"""
edges[0] = [2, 3]
edges[1] = [3, 2]
edges[2] = [6, 4]
edges[3] = [2, 6]
edges[4] = [5, 1]
edges[5] = [1, 3]
edges[6] = [6, 6]

while True:
  s = input()
  if s == "#":
    break
  node = 0
  for c in s:
    node = edges[node][int(c)]
  if node == 1:
    print("Yes")
  else:
    print("No")

Submission status: Accepted

Solution code:
dic={"A":{"0":"X","1":"Y"},
     "X":{"0":"E","1":"Z"},
     "Y":{"0":"X","1":"E"},
     "Z":{"0":"W","1":"B"},
     "W":{"0":"B","1":"Y"},
     "B":{"0":"Y","1":"X"},
     "E":{"0":"E","1":"E"}}

while True:
    route=raw_input()
    if route=="#":break
    state="A"
    for r in route:
        state=dic[state][r]
    print "Yes" if state=="B" else "No"

Submission status: Accepted

Solution code:
t = [[1,2],[-1,3],[1,-1],[4,5],[5,2],[2,1]]
while 1:
    s = raw_input()
    if s=='#': break
    q = 0
    for i in xrange(len(s)):
        if q==-1: break
        q = t[q][int(s[i])]
    print "Yes" if q==5 else "No"

Submission status: Accepted

Solution code:
root = [[1,2],[-1,3],[1,-1],[4,5],[5,2],[2,1]]
while 1:
	n = raw_input()
	if n == "#": break
	cur = 0
	for i in n:
		cur = root[cur][int(i)]
		if cur == -1: break
	print "Yes" if cur == 5 else "No"

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Aka-beko and 40 Thieves
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0266

"""
import sys


def solve(s):
    path = {'A': {'0': 'X', '1': 'Y'}, 'B': {'0': 'Y', '1': 'X'},
    'W': {'0': 'B', '1': 'Y'}, 'X': {'0': None, '1': 'Z'}, 'Y': {'0': 'X', '1': None}, 'Z': {'0': 'W', '1': 'B'}}
    pos = 'A'
    for ch in s:
        pos = path[pos][ch]
        if pos is None:
            return 'No'
    return 'Yes' if pos == 'B' else 'No'


def main(args):
    while True:
        s = input()
        if s == '#':
            break
        ans = solve(s)
        print(ans)


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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

while True:
    S = input()
    if S == "#":
        break
    
    status = "A"
    
    for i in range(len(S)):
        if status == "A":
            if S[i] == "0":
                status = "X"
            else:
                status = "Y"
        elif status == "B":
            if S[i] == "0":
                status = "Y"
            else:
                status = "X"
        elif status == "X":
            if S[i] == "0":
                status = "NA"
            else:
                status = "Z"
        elif status == "Y":
            if S[i] == "0":
                status = "X"
            else:
                status = "NA"
        elif status == "Z":
            if S[i] == "0":
                status = "W"
            else:
                status = "B"
        elif status == "W":
            if S[i] == "0":
                status = "B"
            else:
                status = "Y"
        else:
            status = "NA"
    
    if status == "B":
        print("Yes")
    else:
        print("No")