33032023-02-24 18:32:2312BotiHanoi tornyai variáns (45)python3Wrong answer 0/45123ms24788 KiB
current = [[int(x) - 1 for x in input().split()[:-1]] for _ in range(3)]
wanted = [[int(x) - 1 for x in input().split()[:-1]] for _ in range(3)]

N = max(max(t) for t in current) + 1

pos = [-1] * N
for t in range(3):
    for d in current[t]:
        pos[d] = t

wantedpos = [-1] * N
for t in range(3):
    for d in wanted[t]:
        wantedpos[d] = t

other = [
    [-1, 2, 1],
    [2, -1, 0],
    [1, 0, -1],
]

moves = []


def move(d, to):
    if pos[d] == to:
        return
    # print(f"move {d+1} to tower {to}")
    for e in range(d - 1, -1, -1):
        move(e, other[pos[d]][to])
    moves.append((pos[d], to))
    pos[d] = to


for d in range(N - 1, -1, -1):
    # print("doing", d + 1)
    move(d, wantedpos[d])

print(len(moves))
for f, t in moves:
    print(f + 1, t + 1)
SubtaskSumTestVerdictTimeMemory
base0/45
1Wrong answer0/018ms11744 KiB
2Runtime error0/017ms12032 KiB
3Runtime error0/218ms12180 KiB
4Runtime error0/217ms12624 KiB
5Wrong answer0/217ms12712 KiB
6Wrong answer0/318ms13024 KiB
7Wrong answer0/217ms13076 KiB
8Wrong answer0/217ms13004 KiB
9Wrong answer0/217ms13376 KiB
10Wrong answer0/217ms13576 KiB
11Wrong answer0/217ms13820 KiB
12Wrong answer0/218ms13936 KiB
13Wrong answer0/225ms15080 KiB
14Wrong answer0/229ms15792 KiB
15Wrong answer0/263ms18720 KiB
16Wrong answer0/285ms20620 KiB
17Wrong answer0/279ms20216 KiB
18Wrong answer0/2122ms24340 KiB
19Wrong answer0/379ms20924 KiB
20Wrong answer0/3115ms23592 KiB
21Wrong answer0/3123ms24788 KiB
22Wrong answer0/397ms22000 KiB