QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#345237#7933. Build PermutationybyTL 1ms3932kbC991000b2024-03-06 17:05:262024-03-06 17:05:27

Judging History

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

  • [2024-03-06 17:05:27]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:3932kb
  • [2024-03-06 17:05:26]
  • 提交

answer

#include <stdio.h>

#define N 200020

typedef struct {
    int fi;
    int se;
} ii;

int main() {
    int n;
    scanf("%d", &n);
    ii a[N];
    for (int i = 0; i < n; ++i) {
        scanf("%d", &a[i].fi);
        a[i].se = i + 1;
    }
    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
            if (a[i].fi > a[j].fi) {
                ii temp = a[i];
                a[i] = a[j];
                a[j] = temp;
            }
        }
    }
    int ans[N];
    int sum = a[0].fi + a[n - 1].fi;
    int l = 0, r = n - 1;
    int can = 1;
    while (l <= r) {
        ans[a[l].se - 1] = a[r].se;
        ans[a[r].se - 1] = a[l].se;
        if (a[l].fi + a[r].fi != sum) {
            can = 0;
            break;
        }
        l++;
        r--;
    }
    if (can) {
        for (int i = 0; i < n; ++i)
            printf("%d ", ans[i]);
        printf("\n");
    } else {
        printf("-1\n");
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3932kb

input:

5
4 2 5 1 3

output:

2 1 4 3 5 

result:

ok 

Test #2:

score: 0
Accepted
time: 1ms
memory: 3888kb

input:

3
2 2 3

output:

-1

result:

ok 

Test #3:

score: -100
Time Limit Exceeded

input:

199528
581552649 419782901 924554494 589802859 878336763 659984178 419820729 521791999 956262027 523946290 442086405 808419260 875183942 860794919 584899704 494193909 687014591 794119827 641706288 734029639 795387770 803653459 889799156 455122734 655375888 757642629 427654115 987811208 593072829 584...

output:


result: