20072022-12-13 21:58:41neszbalVárosnézéspython3Wrong answer 0/100338ms12936 KiB
def minimize_phi(n, k, sequence, distances):
    # Initialize the current value of the phi coefficient.
    phi = 0
    for i in range(n):
        for j in range(i + 1, n):
            if sequence[i] > sequence[j]:
                phi += 1

    # Iterate over the allowed distances.
    for d in distances:
        # Check all pairs of attractions that are d positions apart.
        for i in range(n - d):
            j = i + d
            if sequence[i] > sequence[j]:
                # If the order of the attractions would result in a higher phi coefficient,
                # we can swap them to decrease the phi coefficient.
                sequence[i], sequence[j] = sequence[j], sequence[i]
                phi -= 1

    return sequence

n, k = map(int, input().split())
a = list(map(int, input().split()))
d = list(map(int, input().split()))


#print (minimize_phi(n,k, a, d)) # This is the function call
print(*minimize_phi(n,k, a, d))
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted17ms11108 KiB
2Accepted17ms11396 KiB
subtask20/10
3Accepted17ms11688 KiB
4Wrong answer17ms11896 KiB
5Accepted17ms11960 KiB
6Wrong answer17ms11992 KiB
7Wrong answer17ms12476 KiB
subtask30/30
8Wrong answer17ms12656 KiB
9Wrong answer17ms12760 KiB
10Wrong answer17ms12708 KiB
11Wrong answer17ms12720 KiB
12Accepted17ms12936 KiB
subtask40/60
13Time limit exceeded300ms6220 KiB
14Time limit exceeded282ms6092 KiB
15Time limit exceeded268ms6392 KiB
16Time limit exceeded270ms6660 KiB
17Time limit exceeded275ms6608 KiB
18Time limit exceeded279ms6568 KiB
19Time limit exceeded275ms6496 KiB
20Time limit exceeded270ms6820 KiB
21Time limit exceeded338ms6776 KiB
22Time limit exceeded268ms6708 KiB