QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#356749 | #7933. Build Permutation | lucasrpatten | WA | 10ms | 10404kb | Python3 | 868b | 2024-03-18 10:40:35 | 2024-03-18 10:40:36 |
Judging History
answer
from queue import PriorityQueue
n = int(input())
a = [int(i) for i in input().split()]
q1 = PriorityQueue()
q2 = PriorityQueue()
half = n // 2
odd = not n % 2 == 0
for i,v in enumerate(a):
if i <= half:
q1.put((v, i))
elif odd and i == half+1:
q1.put((v,i))
q2.put((-v,i))
else:
q2.put((-v, i))
ne = 0
for i in range(half):
x = q1.get()
y = q2.get()
# if ne == 0:
# ne = abs(x[0])+abs(y[0])
# elif abs(x[0])+abs(y[0]) != ne:
# print(x[0], x[1])
# print(-1)
# exit()
if x[1] > y[1]:
a[x[1]]=abs(y[0])
a[y[1]]=abs(x[0])
elif x[1] == y[1]:
a[x[1]] = a[y[1]] = abs(y[0])
else:
a[y[1]] = abs(y[0])
a[x[1]] = abs(x[0])
if len(a) != len(set(a)):
print(-1)
exit()
print(*a, sep=' ')
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 10ms
memory: 10404kb
input:
5 4 2 5 1 3
output:
4 2 5 1 3
result:
wrong answer