0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-09-19 22:25:27 +00:00

B - Shoe Shuffling

https://codeforces.com/contest/1691/submission/159005479
This commit is contained in:
Baoshuo Ren 2022-05-31 22:50:56 +08:00
parent bb793f7806
commit 32a10dc611
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A

57
Codeforces/1691/B/B.cpp Normal file
View File

@ -0,0 +1,57 @@
#include <iostream>
#include <unordered_map>
#include <vector>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 1e5 + 5;
int t, n, a[N];
std::unordered_map<int, std::vector<int>> map;
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> t;
while (t--) {
map.clear();
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
map[a[i]].push_back(i);
}
bool flag = true;
for (auto it : map) {
if (it.second.size() < 2) {
flag = false;
break;
}
}
if (flag) {
for (int i = 1; i <= n; i++) {
if (map[a[i]].size() > 1) {
cout << map[a[i]][1] << ' ';
map[a[i]].erase(map[a[i]].begin() + 1);
} else {
cout << map[a[i]][0] << ' ';
map[a[i]].clear();
}
}
cout << endl;
} else {
cout << -1 << endl;
}
}
return 0;
}