20042022-12-13 21:48:52neszbalVárosnézéspython3Wrong answer 0/100275ms13088 KiB
def phi(p):
    phi = 0
    for i in range(len(p)):
        for j in range(i+1, len(p)):
            if p[i] > p[j]:
                phi += 1
    return phi

# Read input
n, k = map(int, input().split())
p = list(map(int, input().split()))
l = list(map(int, input().split()))

# Initialize variables
best_p = p.copy()
best_phi = phi(p)

# Try all possible exchanges
for i in range(n):
    for j in range(i+1, n):
        if abs(i - j) in l:  # Check if the distance is allowed
            p[i], p[j] = p[j], p[i]  # Exchange
            phi_p = phi(p)
            if phi_p < best_phi:  # Check if it's better than the current best
                best_p = p.copy()
                best_phi = phi_p
            p[i], p[j] = p[j], p[i]  # Undo the exchange

# Print the result
print(" ".join(map(str, best_p)))
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted18ms11280 KiB
2Wrong answer17ms11364 KiB
subtask20/10
3Accepted17ms11704 KiB
4Wrong answer17ms11884 KiB
5Wrong answer17ms12068 KiB
6Wrong answer17ms12304 KiB
7Wrong answer17ms12620 KiB
subtask30/30
8Wrong answer35ms12368 KiB
9Wrong answer215ms12592 KiB
10Wrong answer92ms12936 KiB
11Time limit exceeded268ms12880 KiB
12Wrong answer43ms13088 KiB
subtask40/60
13Time limit exceeded263ms6180 KiB
14Time limit exceeded259ms6176 KiB
15Time limit exceeded259ms6120 KiB
16Time limit exceeded254ms6160 KiB
17Time limit exceeded275ms6256 KiB
18Time limit exceeded266ms6068 KiB
19Time limit exceeded270ms6296 KiB
20Time limit exceeded266ms6624 KiB
21Time limit exceeded275ms6644 KiB
22Time limit exceeded263ms6656 KiB