记录:网页链接
代码:
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>
#include <utility>
#include <map>
#include <set>
using namespace std;
// #define IS_ATCODER
// #define IS_MULTI_TESTS
// #define USE_CIN
#ifndef ONLINE_JUDGE
#include <atcoder/all>
using mint = atcoder::modint998244353;
#else
#ifdef IS_ATCODER
#include <atcoder/all>
using mint = atcoder::modint998244353;
#endif
#endif
#define mp make_pair
#define fi first
#define se second
#define bg begin()
#define ed end()
#define pb push_back
#define sz(a) int(a.size())
using ll = long long;
using pii = pair <int, int>;
inline int read(){
int ret = 0;
char ch = ' ', c = getchar();
while(!('0' <= c && c <= '9')) ch = c, c = getchar();
while('0' <= c && c <= '9'){
ret = ret * 10 + (c ^ 48);
c = getchar();
}
return ch == '-' ? -ret : ret;
}
map<int, int> cnt, empty_map;
vector<pii> vct[2];
vector<int> ans;
void calc(vector<pii> &vec){
for(int i = 0; i < sz(vec); i += 2){
auto [_00, _01] = vec[i];
auto [_10, _11] = vec[i + 1];
if(_00 > _01) swap(_00, _10), swap(_01, _11);
while(_00){
ans.pb(_01);
ans.pb(_11);
_00--;
_10--;
}
while(_10){
ans.pb(_11);
_10--;
}
}
}
void solve(){
int n = read();
for(int i = 0; i < n; i++) cnt[read()]++;
if(sz(cnt) & 1){
printf("-1\n");
return ;
}
for(auto [x, y]: cnt){
vct[y & 1].pb(mp(y, x));
}
cnt.clear();
cnt = empty_map;
if((sz(vct[0]) & 1) || (sz(vct[1]) & 1)){
printf("-1\n");
return ;
}
sort(vct[0].bg, vct[0].ed);
sort(vct[1].bg, vct[1].ed);
calc(vct[0]), calc(vct[1]);
vct[0].clear(), vct[0].shrink_to_fit();
vct[1].clear(), vct[1].shrink_to_fit();
for(int x: ans) printf("%d ", x);
printf("\n");
ans.clear(), ans.shrink_to_fit();
}
int main(){
#ifdef USE_CIN
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
#endif
#ifdef IS_MULTI_TESTS
int T;
#ifdef USE_CIN
cin >> T;
#else
T = read();
#endif
while(T--) solve();
#else
solve();
#endif
return 0;
}