QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#356749#7933. Build PermutationlucasrpattenWA 10ms10404kbPython3868b2024-03-18 10:40:352024-03-18 10:40:36

Judging History

你现在查看的是最新测评结果

  • [2024-03-18 10:40:36]
  • 评测
  • 测评结果:WA
  • 用时:10ms
  • 内存:10404kb
  • [2024-03-18 10:40:35]
  • 提交

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