QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#357664 | #7933. Build Permutation | lucasrpatten | RE | 0ms | 0kb | Python3 | 1.2kb | 2024-03-19 07:27:57 | 2024-03-19 07:27:57 |
answer
from queue import PriorityQueue
n = int(input())
a = [int(i) for i in input().split()]
q1 = PriorityQueue()
q2 = PriorityQueue()
half = n //2
odd = n % 2 != 0
odd_one = None
for i, v in enumerate(a):
i+=1
q1.put((v, i))
q2.put((-v, i))
ne = 0
for i in range(half+int(odd)):
x = q1.get()
y = q2.get()
x0 = abs(x[0])
y0 = abs(y[0])
if ne == 0:
ne = x0+y0
elif x0+y0 != ne:
print(-1)
exit()
if x0 > y0:
a[y[1]-1] = y[1]
a[x[1]-1] = x[1]
else:
a[y[1]-1] = x[1]
a[x[1]-1] = y[1]
print(*a, sep=' ')
from queue import PriorityQueue
n = int(input())
a = [int(i) for i in input().split()]
q1 = PriorityQueue()
q2 = PriorityQueue()
half = n //2
odd = n % 2 != 0
odd_one = None
for i, v in enumerate(a):
i+=1
q1.put((v, i))
q2.put((-v, i))
ne = 0
for i in range(half+int(odd)):
x = q1.get()
y = q2.get()
x0 = abs(x[0])
y0 = abs(y[0])
if ne == 0:
ne = x0+y0
elif x0+y0 != ne:
print(-1)
exit()
if x0 > y0:
a[y[1]-1] = y[1]
a[x[1]-1] = x[1]
else:
a[y[1]-1] = x[1]
a[x[1]-1] = y[1]
print(*a, sep=' ')
詳細信息
Test #1:
score: 0
Dangerous Syscalls
input:
5 4 2 5 1 3
output:
2 1 4 3 5