97912024-03-06 21:54:44birozsKörJáték (50 pont)python3Accepted 50/50128ms23436 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] * (N + 1)
for i in range(1,N+1):
    hely[lista[i]] = 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
base50/50
1Accepted0/017ms11456 KiB
2Accepted0/017ms11656 KiB
3Accepted0/017ms11816 KiB
4Accepted2/217ms11572 KiB
5Accepted2/217ms11972 KiB
6Accepted2/217ms12096 KiB
7Accepted2/217ms12204 KiB
8Accepted2/217ms11964 KiB
9Accepted2/218ms12544 KiB
10Accepted2/217ms12460 KiB
11Accepted2/217ms12604 KiB
12Accepted2/217ms12880 KiB
13Accepted2/218ms12908 KiB
14Accepted2/217ms12804 KiB
15Accepted2/218ms13228 KiB
16Accepted1/117ms13364 KiB
17Accepted2/2126ms22100 KiB
18Accepted2/2128ms22212 KiB
19Accepted2/2119ms21448 KiB
20Accepted2/2123ms22056 KiB
21Accepted2/2120ms21484 KiB
22Accepted2/2125ms22824 KiB
23Accepted2/2119ms22076 KiB
24Accepted2/2127ms22720 KiB
25Accepted2/2126ms22632 KiB
26Accepted2/2126ms23044 KiB
27Accepted2/2127ms23236 KiB
28Accepted2/2126ms23400 KiB
29Accepted1/1126ms23436 KiB