20062022-12-13 21:52:55neszbalVárosnézéspython3Wrong answer 0/100342ms12776 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))
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Wrong answer17ms10880 KiB
2Wrong answer17ms11708 KiB
subtask20/10
3Wrong answer16ms11528 KiB
4Wrong answer17ms11636 KiB
5Wrong answer16ms11632 KiB
6Wrong answer16ms11812 KiB
7Wrong answer16ms11916 KiB
subtask30/30
8Wrong answer17ms11944 KiB
9Wrong answer17ms12392 KiB
10Wrong answer17ms12476 KiB
11Wrong answer17ms12680 KiB
12Wrong answer17ms12776 KiB
subtask40/60
13Time limit exceeded300ms6144 KiB
14Time limit exceeded263ms6340 KiB
15Time limit exceeded279ms6344 KiB
16Time limit exceeded342ms6664 KiB
17Time limit exceeded259ms6896 KiB
18Time limit exceeded275ms6832 KiB
19Time limit exceeded270ms7024 KiB
20Time limit exceeded279ms6808 KiB
21Time limit exceeded263ms6996 KiB
22Time limit exceeded282ms7108 KiB