QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#472161 | #6414. Classical Maximization Problem | UESTC_DebugSimulator# | WA | 1ms | 5664kb | C++17 | 2.7kb | 2024-07-11 14:47:03 | 2024-07-11 14:47:04 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define lowbit(i) (i&-i)
#define rand() (myrand())
using namespace std;
mt19937 myrand(time(0));
const int maxn = 5e5 + 5;
int n, _, cx[maxn], cy[maxn], vis[maxn];
struct node{
int x, y;
}a[maxn];
void solve() {
cin >> n;
n <<= 1;
vector<int>px, py;
vector<pair<int, int> >ans;
priority_queue<pair<int, int> >qx, qy;
map<pair<int, int>, int>id;
int num = 0;
for (int i = 1 ; i <= n ; ++i) {
int x, y;
cin >> x >> y;
a[i].x = x, a[i].y = y;
id[{x, y}] = i;
vis[i] = 0;
if (!cx[x]) px.push_back(x);
if (!cy[y]) py.push_back(y);
cx[x]++, cy[y]++;
}
for (auto x : px) qx.push({cx[x], x});
for (auto y : py) qy.push({cy[y], y});
while(1) {
pair<int, int>t1, t2, t, p1, p2;
int maxh = -1, f = 0;
if (qx.size() >= 2 && qy.size() >= 1) {
t1 = qx.top();qx.pop();
t2 = qx.top();qx.pop();
t = qy.top();qy.pop();
if (t.first - 2 >= 0) {
int last = maxh;
maxh = max(maxh, min({t1.first - 1, t2.first - 1, t.first - 2}));
if (maxh > last) {
p1.second = p2.second = t.second;
p1.first = t1.second;
p2.first = t2.second;
}
f = 1;
}
qx.push(t1);
qx.push(t2);
qy.push(t);
}
if (qx.size() >= 1 && qy.size() >= 2) {
t1 = qy.top();qy.pop();
t2 = qy.top();qy.pop();
t = qx.top();qx.pop();
if (t.first - 2 >= 0) {
int last = maxh;
maxh = max(maxh, min({t1.first - 1, t2.first - 1, t.first - 2}));
if (maxh > last) {
p1.first = p2.first = t.second;
p1.second = t1.second;
p2.second = t2.second;
}
f = 2;
}
qy.push(t1);
qy.push(t2);
qx.push(t);
}
if (!f) break;
num++;
if (f == 1) {
t1 = qx.top();qx.pop();
t2 = qx.top();qx.pop();
t = qy.top();qy.pop();
t1.first--;
t2.first--;
t.first -= 2;
if (t1.first > 0) qx.push(t1);
if (t2.first > 0) qx.push(t2);
if (t.first > 0) qy.push(t);
}
else {
t1 = qy.top();qy.pop();
t2 = qy.top();qy.pop();
t = qx.top();qx.pop();
t1.first--;
t2.first--;
t.first -= 2;
if (t1.first > 0) qy.push(t1);
if (t2.first > 0) qy.push(t2);
if (t.first > 0) qx.push(t);
}
ans.push_back({id[p1], id[p2]});
vis[id[p1]] = vis[id[p2]] = 1;
}
vector<int>res;
for (int i = 1 ; i <= n ; ++i) {
if (!vis[i]) res.push_back(i);
}
for (int i = 0 ; i < res.size() ; i += 2) ans.push_back({res[i], res[i + 1]});
cout << num << '\n';
for (auto [x, y] : ans) cout << x << ' ' << y << '\n';
for (int i = 1 ; i <= n ; ++i) cx[a[i].x] = cy[a[i].y] = 0;
}
signed main(void) {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> _;
while(_--) solve();
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 5664kb
input:
3 2 0 0 0 1 1 0 1 1 2 0 0 0 1 0 2 0 3 2 0 0 1 1 2 2 3 3
output:
2 4 2 2 1 3 0 2 4 3 2 1 0 1 2 3 4
result:
wrong answer point 2 used twice (test case 1)