QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#414975 | #7933. Build Permutation | pkien01 | WA | 0ms | 3552kb | C++23 | 804b | 2024-05-20 06:16:15 | 2024-05-20 06:16:17 |
Judging History
answer
/*input
3
2 2 3
*/
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
if (n == 1) {
cout << 0 << endl;
}
else {
vector<int> arr(n);
for (int i = 0; i < n; i++) cin >> arr[i];
vector<int> perm(n);
iota(perm.begin(), perm.end(), 0);
sort(perm.begin(), perm.end(), [&](int i, int j) {return arr[i] < arr[j];});
bool sol = true;
int sum = arr[perm.front()] + arr[perm.back()];
for (int i = 1; i != n - i; i++) {
if (arr[perm[i]] + arr[perm[n - i - 1]] != sum) {
sol = false;
break;
}
}
if (!sol) {
cout << -1 << endl;
} else {
vector<int> ans(n);
for (int i = 0; i < n; i++) ans[perm[i]] = perm[n - i - 1];
for (int i = 0; i < n; i++) cout << ans[i] + 1<< " ";
cout << endl;
}
}
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3552kb
input:
5 4 2 5 1 3
output:
-1
result:
wrong answer Integer -1 violates the range [1, 5]