Rezultati

Up. imeNalogaJezikRezultatČas oddaje
jayzcrew-2018 Zaletavanje Python 3 100/100OK 19. apr '18 @ 18:35

Test Točke Porabljen spomin Porabljen čas Status
#1 14/14 8,668 MiB 0,000 s OK
#2 14/14 8,594 MiB 0,000 s OK
#3 14/14 8,496 MiB 0,000 s OK
#4 14/14 8,688 MiB 0,000 s OK
#5 14/14 8,605 MiB 0,000 s OK
#6 15/15 8,570 MiB 0,000 s OK
#7 15/15 8,539 MiB 0,000 s OK

Ocenjevani program (hitnrun.py):
N,W,H = list(map(int, input().strip().split()))

cars = []

for k in range(N):
    S,X,Y = input().strip().split()
    cars.append((k, S,int(X),int(Y)))

diags = dict()

for k,S,x,y in cars:
    d = x+y
    if d not in diags:
        diags[d] = []
    diags[d].append((k,S,x,y))
#
# for e in diags:
#     print(e, diags[e])


def solve(diag, W, H):
    cars = []
    for k,S,x,y in diag:
        cars.append([x,y,k,S])
    cars.sort(reverse=True)

    finish = []
    zaleteli_smo_se = 0
    for i in range(len(cars)):
        if cars[0] != False:
            x, y, k, S = cars[i]
            if S == 'D':
                finish.append((k, W, y))
            else:
                j = i+1
                while j < len(cars):
                    if cars[j][0] != False:
                        if cars[j][3] == "D":
                            finish.append((k,W,cars[j][1]))
                            prejsn = j
                            while j-1 > i:
                                if cars[j][0] != False:
                                    cars[j][3] = cars[prejsn][3]
                                    prejsn = j
                                j-=1
                    j+=1
    return finish


def solve2(diag, W, H):
    cars = []

    for k,S,x,y in diag:
        cars.append([x,y,k,S])
    cars.sort(reverse=True)

    finish = []

    while len(cars) > 0:
        while len(cars) > 0 and cars[0][3] == 'D':
            x,y,k,S = cars[0]
            finish.append([k,W,y])
            cars = cars[1:]
        while len(cars) > 0 and cars[-1][3] == 'G':
            x,y,k,S = cars[-1]
            finish.append([k,x,H])
            cars = cars[:-1]

        if len(cars) == 0:
            break

        mintime = 10**12

        for i in range(len(cars) - 1):
            if cars[i][3] == 'G' and cars[i+1][3] == 'D':
                mintime = min(mintime, cars[i+1][1] - cars[i][1])

        # Izvedemo zamik

        for i in range(len(cars)):
            x,y,k,S = cars[i]
            if S == 'G':
                cars[i] = [x,y+mintime,k,S]
            else:
                cars[i] = [x+mintime,y,k,S]

        for i in range(len(cars) - 1):
            if cars[i][0] == cars[i+1][0]:
                cars[i][3] = 'D'
                cars[i+1][3] = 'G'

    return finish



end = []



for d in diags:
    res = solve2(diags[d],W,H)
    end.extend(res)

end.sort()
for k,x,y in end:
    print(x,y)