40% W.A ?? Passou em todos os casos do toolkit.

Leticia asked 2 years ago

def get_columns(matrix):
    dinamic = 'zip('
    for i in range(len(matrix)):
        dinamic += 'matrix[%d],'%i
    dinamic = dinamic.strip(',') + ')'
    return eval(dinamic)

def validate_sequence(sequence):
    #para validar linhas e colunas
    #n tem problema porque as strings tem so 1 digito
    return True if sorted(sequence) == ['1','2','3','4','5','6','7','8','9'] else False

def main():
    matrix = []
    for i in range(9):
        sequence = input().split()
        if not validate_sequence(sequence):
            return 'NAO'            

    for column in get_columns(matrix):
        if not validate_sequence(column):           
            return 'NAO'

    for i in range(0, 9, 3):
        groups = list(get_columns(matrix[i: i + 3]))                
        for n in range(0, 9, 3):
            group = ''.join([number for sequence in groups[n: n + 3] for number in sequence])
            if not validate_sequence(group):                
                return 'NAO'
    return 'SIM'

cases = int(input())
for i in range(cases):
    print('Instancia {}\n{}\n'.format(i + 1, main()))

This topic has not been answered yet. Be the first!

Remember not post solutions. Your post may be reviewed by our moderators.