QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#363758 | #7933. Build Permutation | biz11 | WA | 234ms | 147304kb | C++20 | 2.3kb | 2024-03-24 02:59:35 | 2024-03-24 02:59:37 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int INF = INT_MAX;
int NEG_INF = INT_MIN;
template <class T1, class T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
return os << '{' << p.first << ", " << p.second << '}';
}
template <class T, class = decay_t<decltype(*begin(declval<T>()))>,
class = enable_if_t<!is_same<T, string>::value>>
ostream &operator<<(ostream &os, const T &c) {
os << '[';
for (auto it = c.begin(); it != c.end(); ++it)
os << &", "[2 * (it == c.begin())] << *it;
return os << ']';
}
//support up to 5 args
#define _NTH_ARG(_1, _2, _3, _4, _5, _6, N, ...) N
#define _FE_0(_CALL, ...)
#define _FE_1(_CALL, x) _CALL(x)
#define _FE_2(_CALL, x, ...) _CALL(x) _FE_1(_CALL, __VA_ARGS__)
#define _FE_3(_CALL, x, ...) _CALL(x) _FE_2(_CALL, __VA_ARGS__)
#define _FE_4(_CALL, x, ...) _CALL(x) _FE_3(_CALL, __VA_ARGS__)
#define _FE_5(_CALL, x, ...) _CALL(x) _FE_4(_CALL, __VA_ARGS__)
#define FOR_EACH_MACRO(MACRO, ...) \
_NTH_ARG(dummy, ##__VA_ARGS__, _FE_5, _FE_4, _FE_3, _FE_2, _FE_1, _FE_0) \
(MACRO, ##__VA_ARGS__)
//Change output format here
#define out(x) "\033[31m" #x " = " << x << "; \033[0m"
#define dbg(...) \
cerr << "\033[31m" << "Line " << __LINE__ << ": " << "\033[0m" FOR_EACH_MACRO(out, __VA_ARGS__) << "\n"
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin>>n;
map<int, deque<int>> m;
vi l;
rep(i,0,n) {
int k;
cin >> k;
m[k].push_back(i);
l.push_back(k);
}
ll tot = accumulate(all(l),0)*2/sz(l);
int i=0;
vi out;
int k;
rep(it, begin(l), end(l)) {
i++;
int k = *it;
ll x=tot-k;
// dbg(x, m[x]);
if (!m[x].empty()) {
out.push_back(m[x].front());
m[x].pop_front();
}
else {
break;
}
}
// dbg(out,l,sz(out),sz(l));
if (sz(out) != sz(l)) {
cout << -1;
}
else {
rep(x, begin(out),end(out)) cout << *x+1 << " ";
}
cout << endl;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3824kb
input:
5 4 2 5 1 3
output:
2 1 4 3 5
result:
ok
Test #2:
score: 0
Accepted
time: 0ms
memory: 3604kb
input:
3 2 2 3
output:
-1
result:
ok
Test #3:
score: 0
Accepted
time: 173ms
memory: 147304kb
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: 234ms
memory: 147268kb
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]