97902024-03-06 21:44:01birozsKörJáték (50 pont)python3Time limit exceeded 25/50600ms13696 KiB
N = int(input())
lista = list(map(int,input().split()))
lista.insert(0,0)
#N = 5
#lista = [0,3,5,2,1,4]
hely = [0]
for i in range(1,N+1):
    hely.append(lista.index(i))
#print(hely)
def tavolsag(i,j):
    if i <= j:
        return j - i
    else:
        return N + j - i
kovetkezo = [0]
for i in range(1,N):
    kovetkezo.append(tavolsag(hely[i],hely[i+1]))

kovetkezo.append(0)
#print(kovetkezo)
alap = sum(kovetkezo)
for i in range(1,N+1):
    osszeg = alap
    if lista[i] == N:
        print(osszeg)
    else:
        osszeg += tavolsag(hely[N],hely[lista[i]])
        osszeg -= kovetkezo[lista[i]]
        if lista[i] > 1 and lista[i] < N:
            osszeg -= kovetkezo[lista[i]-1]
            osszeg += tavolsag(hely[lista[i]-1],hely[lista[i]+1])
        print(osszeg)
SubtaskSumTestVerdictTimeMemory
base25/50
1Accepted0/018ms11392 KiB
2Accepted0/017ms11532 KiB
3Accepted0/018ms11600 KiB
4Accepted2/217ms12208 KiB
5Accepted2/218ms12204 KiB
6Accepted2/217ms12372 KiB
7Accepted2/217ms12584 KiB
8Accepted2/217ms12376 KiB
9Accepted2/217ms12528 KiB
10Accepted2/217ms12820 KiB
11Accepted2/217ms13212 KiB
12Accepted2/218ms13316 KiB
13Accepted2/217ms13276 KiB
14Accepted2/217ms13392 KiB
15Accepted2/217ms12884 KiB
16Accepted1/118ms13696 KiB
17Time limit exceeded0/2600ms9352 KiB
18Time limit exceeded0/2555ms9580 KiB
19Time limit exceeded0/2580ms9460 KiB
20Time limit exceeded0/2572ms9404 KiB
21Time limit exceeded0/2564ms9328 KiB
22Time limit exceeded0/2555ms9276 KiB
23Time limit exceeded0/2560ms9280 KiB
24Time limit exceeded0/2583ms9532 KiB
25Time limit exceeded0/2551ms9652 KiB
26Time limit exceeded0/2572ms9884 KiB
27Time limit exceeded0/2575ms9960 KiB
28Time limit exceeded0/2560ms9916 KiB
29Time limit exceeded0/1564ms9912 KiB