Rezultati

Up. imeNalogaJezikRezultatČas oddaje
muzik-2018 Puzzle Python 3 100/100OK 19. apr '18 @ 18:24

Test Točke Porabljen spomin Porabljen čas Status
#1 10/10 8,430 MiB 0,000 s OK
#2 10/10 8,336 MiB 0,000 s OK
#3 10/10 8,324 MiB 0,000 s OK
#4 10/10 8,422 MiB 0,000 s OK
#5 10/10 8,332 MiB 0,000 s OK
#6 10/10 8,422 MiB 0,000 s OK
#7 10/10 8,398 MiB 0,000 s OK
#8 10/10 8,324 MiB 0,000 s OK
#9 10/10 8,348 MiB 0,000 s OK
#10 10/10 8,422 MiB 0,000 s OK

Ocenjevani program (puzle.py):
import sys

#sys.stdin = open("mesta.in")

inp = sys.stdin.readline

N = 9

data = [inp().strip() for j in range(N)]

def rotate(sl, ro):
    return sl[ro:] + sl[:ro]

def all_rot(sl):
    for j in range(4):
        yield rotate(sl, j), j

def izberi_sliko(mask=[0 for _ in range(N)]):
    for i in range(len(data)):
        if mask[i]:
            continue
        sl = data[i]
        for ro in range(0,4):
            tren = rotate(sl, ro), ro, i
            yield tren

def correct(mask, crka: str, ind:int):
    for j in range(N):
        if j in mask:
            continue
        if crka.islower():
            if crka.upper() in data[j]:
                for temp, ro in all_rot(data[j]):
                    if temp[ind] == crka.upper():
                        yield temp, ro, j
        else:
            if crka.lower() in data[j]:
                for temp, ro in all_rot(data[j]):
                    if temp[ind] == crka.lower():
                        yield temp, ro, j


def solve_line3(mask, g1, g2, g3):
    for sl, ro, i in correct(mask, g1, 1):
        # prvo mamo
        # izberemo drugo
        for sl2, ro2, i2 in correct(mask + [i], sl[2], 0):
            if sl2[1].islower():
                if sl2[1].upper() != g2:
                    continue
            else:
                if sl2[1].lower() != g2:
                    continue
            for sl3, ro3, i3 in correct(mask + [i, i2], sl2[2], 0):
                if sl3[1].islower():
                    if sl3[1].upper() != g3:
                        continue
                else:
                    if sl3[1].lower() != g3:
                        continue
                return [(sl, ro, i), (sl2, ro2, i2), (sl3, ro3, i3)]

def solve_line(mask, g1, g2, g3):
    for sl, ro, i in correct(mask, g1, 1):
        # prvo mamo
        # izberemo drugo
        for sl2, ro2, i2 in correct(mask + [i], sl[2], 0):
            if sl2[1].islower():
                if sl2[1].upper() != g2:
                    continue
            else:
                if sl2[1].lower() != g2:
                    continue
            for sl3, ro3, i3 in correct(mask + [i, i2], sl2[2], 0):
                if sl3[1].islower():
                    if sl3[1].upper() != g3:
                        continue
                else:
                    if sl3[1].lower() != g3:
                        continue
                rtr = solve_line3(mask + [i, i2, i3],sl[3],sl2[3],sl3[3])
                if rtr:
                    yield [(sl, ro, i), (sl2, ro2, i2), (sl3, ro3, i3)] + rtr



for sl, ro, i in izberi_sliko():
    # prvo mamo
    # izberemo drugo

    for sl2, ro2, i2 in correct([i], sl[2], 0):
        for sl3, ro3, i3 in correct([i,i2], sl2[2], 0):
            for neki in solve_line([i, i2, i3], sl[3],sl2[3],sl3[3]):
                # Prva vrstica
                print(" " + sl[1] + "  " + sl2[1] + "  " + sl3[1] + " ")
                print(sl[0] + " " + sl[2] + sl2[0] + " " + sl2[2] + sl3[0] + " " + sl3[2])
                print(" " + sl[3] + "  " + sl2[3] + "  " + sl3[3] + " ")
                (sl, *_), (sl2, *_), (sl3, *_)  = neki[:3]
                print(" " + sl[1] + "  " + sl2[1] + "  " + sl3[1] + " ")
                print(sl[0] + " " + sl[2] + sl2[0] + " " + sl2[2] + sl3[0] + " " + sl3[2])
                print(" " + sl[3] + "  " + sl2[3] + "  " + sl3[3] + " ")
                (sl, *_), (sl2, *_), (sl3, *_)  = neki[3:]
                print(" " + sl[1] + "  " + sl2[1] + "  " + sl3[1] + " ")
                print(sl[0] + " " + sl[2] + sl2[0] + " " + sl2[2] + sl3[0] + " " + sl3[2])
                print(" " + sl[3] + "  " + sl2[3] + "  " + sl3[3] + " ")
                sys.exit(0)