2004 | 2022-12-13 21:48:52 | neszbal | Városnézés | python3 | Wrong answer 0/100 | 275ms | 13088 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)))
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 18ms | 11280 KiB | ||||
2 | Wrong answer | 17ms | 11364 KiB | ||||
subtask2 | 0/10 | ||||||
3 | Accepted | 17ms | 11704 KiB | ||||
4 | Wrong answer | 17ms | 11884 KiB | ||||
5 | Wrong answer | 17ms | 12068 KiB | ||||
6 | Wrong answer | 17ms | 12304 KiB | ||||
7 | Wrong answer | 17ms | 12620 KiB | ||||
subtask3 | 0/30 | ||||||
8 | Wrong answer | 35ms | 12368 KiB | ||||
9 | Wrong answer | 215ms | 12592 KiB | ||||
10 | Wrong answer | 92ms | 12936 KiB | ||||
11 | Time limit exceeded | 268ms | 12880 KiB | ||||
12 | Wrong answer | 43ms | 13088 KiB | ||||
subtask4 | 0/60 | ||||||
13 | Time limit exceeded | 263ms | 6180 KiB | ||||
14 | Time limit exceeded | 259ms | 6176 KiB | ||||
15 | Time limit exceeded | 259ms | 6120 KiB | ||||
16 | Time limit exceeded | 254ms | 6160 KiB | ||||
17 | Time limit exceeded | 275ms | 6256 KiB | ||||
18 | Time limit exceeded | 266ms | 6068 KiB | ||||
19 | Time limit exceeded | 270ms | 6296 KiB | ||||
20 | Time limit exceeded | 266ms | 6624 KiB | ||||
21 | Time limit exceeded | 275ms | 6644 KiB | ||||
22 | Time limit exceeded | 263ms | 6656 KiB |