社区讨论
60 pts 求 hack
P13494 【MX-X14-T4】分门别类参与者 2已保存回复 1
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 1 条
- 当前快照
- 1 份
- 快照标识符
- @mdkcewog
- 此快照首次捕获于
- 2025/07/26 22:25 7 个月前
- 此快照最后确认于
- 2025/11/04 03:40 4 个月前
CPP
// Problem: T624699 【MX-X14-T4】分门别类
// Contest: Luogu
// URL: https://www.luogu.com.cn/problem/T624699?contestId=261524
// Memory Limit: 512 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
int t, n, a[N];
pair<int, int> p[N];
vector<vector<int>> ans;
vector<int> v;
map<int, int> c, c2;
bool cmp(pair<int, int> a, pair<int, int> b) { return a.second > b.second; }
int main() {
ios::sync_with_stdio(0), cin.tie(0);
cin >> t;
while (t--) {
c.clear();
c2.clear();
cin >> n;
int ct = 0;
for (int i = 1; i <= n; ++i) {
cin >> a[i], ++c[a[i]];
if (c[a[i]] == 1) ++ct;
}
// if (ct == 1) cout << "-1\n";
// else if (ct == 2) {
// int a = c.begin()->second, va = c.begin()->first;
// c.erase(c.begin());
// int b = c.begin()->second, vb = c.begin()->first;
// if (a == b) {
// cout << a << '\n';
// for (int i = 1; i <= a; ++i)
// cout << "2 " << va << ' ' << vb << '\n';
// } else cout << "-1\n";
// } else if (ct == 3) {
// int a = c.begin()->second, va = c.begin()->first;
// c.erase(c.begin());
// int b = c.begin()->second, vb = c.begin()->first;
// c.erase(c.begin());
// int c = ::c.begin()->second, vc = ::c.begin()->first;
// if (a + b == c) {
// cout << c << '\n';
// for (int i = 1; i <= a; ++i) cout << "2 " << va << ' ' << vc << '\n';
// for (int i = 1; i <= b; ++i) cout << "2 " << vb << ' ' << vc << '\n';
// } else if (a + c == b) {
// cout << b << '\n';
// for (int i = 1; i <= a; ++i) cout << "2 " << va << ' ' << vb << '\n';
// for (int i = 1; i <= c; ++i) cout << "2 " << vc << ' ' << vb << '\n';
// } else if (b + c == a) {
// cout << a << '\n';
// for (int i = 1; i <= b; ++i) cout << "2 " << vb << ' ' << va << '\n';
// for (int i = 1; i <= c; ++i) cout << "2 " << vc << ' ' << va << '\n';
// } else if (!((a + b + c) & 1) && max({ a, b, c }) <= (a + b + c) / 2) {
// cout << (a + b + c) / 2 << '\n';
// int t = (a + b + c) / 2, t1 = b - (t - a), t2 = a - t1;
// for (int i = 1; i <= t1; ++i) cout << "2 " << va << ' ' << vb << '\n';
// for (int i = 1; i <= t2; ++i) cout << "2 " << va << ' ' << vc << '\n';
// for (int i = t1 + t2 + 1; i <= t; ++i) cout << "2 " << vb << ' ' << vc << '\n';
// } else cout << "-1\n";
// } else {
int id = 0, sum = n;
if (n & 1) { cout << "-1\n"; continue; }
ans.clear()/*, ans.shrink_to_fit()*/;
for (auto &x : c) p[++id] = x;
sort(p + 1, p + id + 1, cmp);
if (p[1].second > n / 2) { cout << "-1\n"; continue; }
while (id) {
v.clear();
int cntx = min(sum - 2 * p[1].second + 2, (id / 2) * 2);
for (int i = 1; i <= cntx; ++i) {
v.emplace_back(p[i].first);
--p[i].second;
}
sum -= cntx;
// if (id & 1) {
// for (int i = 1; i <= cntx; ++i) {
// v.emplace_back(p[i].first);
// --p[i].second;
// }
// // int tid = id;
// // while (tid > 1 && p[tid].second > p[tid - 1].second)
// // swap(p[tid], p[tid - 1]), --tid;
// } else {
// for (int i = 1; i <= cntx; ++i) {
// v.emplace_back(p[i].first);
// --p[i].second;
// }
// }
sort(p + 1, p + id + 1, cmp);
while (id && p[id].second == 0) --id;
ans.emplace_back(v);
// ++cnt;
}
// assert(!sum);
cout << ans.size() << '\n';
int s = 0;
for (auto &x : ans) {
cout << x.size() << ' ';
s += x.size();
// assert(!(x.size() & 1));
// for (int i = 0; i + 1 < (int)x.size(); ++i)
// assert(x[i] != x[i + 1]);
for (int i = 0; i < (int)x.size(); ++i) ++c2[x[i]];
sort(x.begin(), x.end());
for (int &y : x) cout << y << ' ';
cout << '\n';
}
// for (auto &x : c)
// assert(c2[x.first] == x.second);
// assert(s == n);
// }
}
return 0;
}
回复
共 1 条回复,欢迎继续交流。
正在加载回复...