Rezultati

Up. imeNalogaJezikRezultatČas oddaje
kjejenovictk-2018 Kvadrat števil Python 3 100/100OK 13. okt '18 @ 15:16

Test Točke Porabljen spomin Porabljen čas Status
#1 10/10 8,676 MiB 0,000 s OK
#2 10/10 8,664 MiB 0,000 s OK
#3 10/10 8,598 MiB 0,000 s OK
#4 10/10 8,523 MiB 0,000 s OK
#5 10/10 8,816 MiB 0,000 s OK
#6 10/10 8,773 MiB 0,000 s OK
#7 10/10 9,422 MiB 0,000 s OK
#8 10/10 9,434 MiB 0,000 s OK
#9 10/10 9,348 MiB 0,000 s OK
#10 10/10 9,512 MiB 0,000 s OK

Ocenjevani program (kvadrat.py):
import sys

sys.setrecursionlimit(10**9)

data = sys.stdin.readlines()

#data = open("kvadrat.txt").readlines()

N = int(data[0])
#N = 13

data = sorted([int(data[i]) for i in range(1, N*N+1)])

#data = [i for i in range(N*N)]
#print(len(data))
#print(N)

loops = []
n_predelanih_indeksov = 0
index = 0

for l in range(int((N-1)/2.0)):
    sirina_loopa = N - 2*l
    n_indeksov = 4*sirina_loopa -4
    loop = [0 for i in range(n_indeksov)]


    index_sprehajanja = 0
    counter = 0
    skok = sirina_loopa - 1
    skok2 = skok
    skok_counter = 0

    while counter < n_indeksov:
        #print("Counter ",counter)
        #print(index_sprehajanja)
        loop[index_sprehajanja] = data[index]

        if skok_counter % 2:
            cur_skok = skok2
        else:
            cur_skok = skok




        if index_sprehajanja + cur_skok >= n_indeksov:
            index_sprehajanja = (index_sprehajanja + skok2) % n_indeksov + 1
            #index_sprehajanja = (index_sprehajanja + skok) % sirina_loopa + 1
            #print("Indeks sprehajanja",index_sprehajanja)

            if index_sprehajanja == sirina_loopa//2:

                skok = sirina_loopa - 1
                skok2 = skok
                #print("Skok na sredini: ", skok)
            else:

                skok = sirina_loopa - 2 * index_sprehajanja - 1
                skok2 = 2*index_sprehajanja
                skok_counter = -1
                #print("Nov Skok", skok)
        else:

            if skok_counter % 2:
                index_sprehajanja += skok2
            else:
                index_sprehajanja += skok

        counter += 1
        index += 1
        skok_counter += 1

    loops.append(loop)

loops.append([data[-1]])

for line in range(N):
    row_string = ""
    for row in range(N):
        loop = min([line,N-line-1,row,N-row-1])
        dist = line + row - 2*loop
        #print(line, row, loop, dist)
        if row:
            row_string += " "
        if line > row:
            row_string +=  str(loops[loop][dist])
        else:
            row_string += str(loops[loop][-dist])
    print(row_string)