10117 | 2024-03-27 11:33:06 | 111 | Játék a síkon | cpp17 | Accepted 100/100 | 293ms | 6488 KiB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
struct P{
int x,y;
};
bool kuhn(vector<vector<int>>& g, vector<int>& b, int i) {
vector<int> v(g.size());
auto dfs = [&](auto self, int i) {
if (v[i]) {
return 0;
}
v[i] = 1;
for (int j : g[i]) {
if (b[j] == -2) {
continue;
}
if (b[j] == -1 || self(self, b[j])) {
b[j] = i;
return 1;
}
}
return 0;
};
return dfs(dfs, i);
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N;
cin>>N;
vector<P>v(N);
for(int i=0;i<N;i++){
cin>>v[i].x>>v[i].y;
}
int p=partition(v.begin(),v.end(),[&](P p){return (p.x&1)==(p.y&1);})-v.begin(); // -5 % 2 = -1
vector<vector<int>>g(p),gg(N-p);
for(int i=0;i<p;i++){
for(int j=p;j<N;j++){
if(abs(v[j].x-v[i].x)+abs(v[j].y-v[i].y)==1){
g[i].push_back(j-p);
gg[j-p].push_back(i);
}
}
}
vector<int>b(N-p,-1),bb(p,-1);
for(int i=0;i<p;i++){
kuhn(g,b,i);
}
for(int i=0;i<N-p;i++){
kuhn(gg,bb,i);
}
vector<int>ans;
for(int i=0;i<N-p;i++){
if(b[i]==-1){
ans.push_back(p+i);
continue;
}
int x=b[i];
b[i]=-2;
if(kuhn(g,b,x)){
ans.push_back(p+i);
b[i]=-1;
}
else{
b[i]=x;
}
}
for(int i=0;i<p;i++){
if(bb[i]==-1){
ans.push_back(i);
continue;
}
int x=bb[i];
bb[i]=-2;
if(kuhn(gg,bb,x)){
ans.push_back(i);
bb[i]=-1;
}
else{
bb[i]=x;
}
}
cout<<ans.size()<<'\n';
for(int i:ans){
cout<<v[i].x<<' '<<v[i].y<<'\n';
}
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1824 KiB | ||||
2 | Accepted | 7ms | 2276 KiB | ||||
subtask2 | 9/9 | ||||||
3 | Accepted | 3ms | 2264 KiB | ||||
4 | Accepted | 3ms | 2480 KiB | ||||
subtask3 | 10/10 | ||||||
5 | Accepted | 3ms | 2588 KiB | ||||
6 | Accepted | 3ms | 2668 KiB | ||||
7 | Accepted | 3ms | 2808 KiB | ||||
8 | Accepted | 3ms | 3040 KiB | ||||
9 | Accepted | 3ms | 3108 KiB | ||||
10 | Accepted | 3ms | 3240 KiB | ||||
11 | Accepted | 3ms | 3332 KiB | ||||
12 | Accepted | 3ms | 3456 KiB | ||||
subtask4 | 10/10 | ||||||
13 | Accepted | 4ms | 3656 KiB | ||||
14 | Accepted | 4ms | 3844 KiB | ||||
15 | Accepted | 4ms | 4064 KiB | ||||
16 | Accepted | 4ms | 4212 KiB | ||||
subtask5 | 16/16 | ||||||
17 | Accepted | 4ms | 4308 KiB | ||||
18 | Accepted | 4ms | 4376 KiB | ||||
19 | Accepted | 4ms | 4380 KiB | ||||
20 | Accepted | 4ms | 4512 KiB | ||||
21 | Accepted | 8ms | 4660 KiB | ||||
subtask6 | 18/18 | ||||||
22 | Accepted | 4ms | 4632 KiB | ||||
23 | Accepted | 4ms | 4556 KiB | ||||
24 | Accepted | 4ms | 4568 KiB | ||||
25 | Accepted | 4ms | 4584 KiB | ||||
26 | Accepted | 4ms | 4700 KiB | ||||
subtask7 | 37/37 | ||||||
27 | Accepted | 20ms | 5312 KiB | ||||
28 | Accepted | 19ms | 5328 KiB | ||||
29 | Accepted | 68ms | 5680 KiB | ||||
30 | Accepted | 293ms | 5756 KiB | ||||
31 | Accepted | 131ms | 5780 KiB | ||||
32 | Accepted | 21ms | 5764 KiB | ||||
33 | Accepted | 32ms | 5344 KiB | ||||
34 | Accepted | 54ms | 5352 KiB | ||||
35 | Accepted | 39ms | 5368 KiB | ||||
36 | Accepted | 24ms | 6008 KiB | ||||
37 | Accepted | 41ms | 6244 KiB | ||||
38 | Accepted | 26ms | 6204 KiB | ||||
39 | Accepted | 75ms | 6332 KiB | ||||
40 | Accepted | 83ms | 6384 KiB | ||||
41 | Accepted | 134ms | 6452 KiB | ||||
42 | Accepted | 86ms | 6488 KiB |