QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#387187 | #7933. Build Permutation | sanspapyrus683# | WA | 49ms | 4004kb | C++17 | 1.1kb | 2024-04-12 08:48:21 | 2024-04-12 08:48:21 |
Judging History
answer
#include <bits/stdc++.h>
#if __has_include("debugging.hpp")
#include "debugging.hpp"
#endif
using namespace std;
int main() {
int n;
cin >> n;
long long total = 0;
vector<int> arr(n);
for (int& i : arr) {
cin >> i;
total += i;
}
long long pair_num = (long long)n * (n - 1) / 2;
if (total * (n - 1) % pair_num != 0) {
cout << -1 << endl;
return 0;
}
long long target = total * (n - 1) / pair_num;
map<int, vector<int>> usable_inds;
for (int i = 0; i < n; i++) {
usable_inds[arr[i]].push_back(i);
}
vector<int> perm(n);
bool valid = true;
for (int i = 0; i < n; i++) {
int match = target - arr[i];
if (usable_inds[match].empty()) {
valid = false;
break;
}
perm[i] = usable_inds[match].back();
usable_inds[match].pop_back();
}
if (valid) {
for (int i = 0; i < n - 1; i++) {
cout << perm[i] + 1 << ' ';
}
cout << perm.back() + 1 << endl;
} else {
cout << -1 << endl;
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3564kb
input:
5 4 2 5 1 3
output:
2 1 4 3 5
result:
ok
Test #2:
score: 0
Accepted
time: 0ms
memory: 3596kb
input:
3 2 2 3
output:
-1
result:
ok
Test #3:
score: 0
Accepted
time: 46ms
memory: 3980kb
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:
-1
result:
ok
Test #4:
score: -100
Wrong Answer
time: 49ms
memory: 4004kb
input:
199680 774760412 315033238 665140012 402128528 221827348 923752357 281703052 551555739 483983889 622621809 949928382 909484599 413397988 424613137 353323926 392255354 551928848 464853065 860603765 618364501 423106762 752293338 551415838 898671881 969815739 150102831 644806419 333507443 379455235 981...
output:
-1
result:
wrong answer Integer -1 violates the range [1, 199680]