10108 | 2024-03-26 22:35:01 | 111 | Játék a síkon | cpp17 | Wrong answer 10/100 | 293ms | 5848 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%2==p.y%2;})-v.begin();
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 | 1828 KiB | ||||
2 | Accepted | 8ms | 2264 KiB | ||||
subtask2 | 0/9 | ||||||
3 | Wrong answer | 3ms | 2252 KiB | ||||
4 | Accepted | 3ms | 2356 KiB | ||||
subtask3 | 0/10 | ||||||
5 | Accepted | 3ms | 2572 KiB | ||||
6 | Accepted | 3ms | 2656 KiB | ||||
7 | Accepted | 3ms | 2796 KiB | ||||
8 | Wrong answer | 3ms | 3012 KiB | ||||
9 | Accepted | 3ms | 3108 KiB | ||||
10 | Accepted | 3ms | 3352 KiB | ||||
11 | Accepted | 2ms | 3252 KiB | ||||
12 | Wrong answer | 3ms | 3256 KiB | ||||
subtask4 | 10/10 | ||||||
13 | Accepted | 4ms | 3464 KiB | ||||
14 | Accepted | 4ms | 3380 KiB | ||||
15 | Accepted | 4ms | 3520 KiB | ||||
16 | Accepted | 4ms | 3572 KiB | ||||
subtask5 | 0/16 | ||||||
17 | Wrong answer | 4ms | 3584 KiB | ||||
18 | Accepted | 4ms | 3696 KiB | ||||
19 | Wrong answer | 4ms | 3608 KiB | ||||
20 | Wrong answer | 4ms | 3632 KiB | ||||
21 | Accepted | 8ms | 3664 KiB | ||||
subtask6 | 0/18 | ||||||
22 | Accepted | 4ms | 3752 KiB | ||||
23 | Wrong answer | 4ms | 3792 KiB | ||||
24 | Wrong answer | 4ms | 3688 KiB | ||||
25 | Wrong answer | 4ms | 3840 KiB | ||||
26 | Wrong answer | 4ms | 3852 KiB | ||||
subtask7 | 0/37 | ||||||
27 | Wrong answer | 18ms | 4360 KiB | ||||
28 | Accepted | 18ms | 4396 KiB | ||||
29 | Accepted | 68ms | 4916 KiB | ||||
30 | Accepted | 293ms | 4880 KiB | ||||
31 | Accepted | 131ms | 4844 KiB | ||||
32 | Accepted | 21ms | 4824 KiB | ||||
33 | Accepted | 32ms | 4468 KiB | ||||
34 | Accepted | 54ms | 4492 KiB | ||||
35 | Accepted | 39ms | 4532 KiB | ||||
36 | Accepted | 24ms | 5060 KiB | ||||
37 | Accepted | 41ms | 5300 KiB | ||||
38 | Accepted | 26ms | 5340 KiB | ||||
39 | Accepted | 75ms | 5608 KiB | ||||
40 | Accepted | 83ms | 5460 KiB | ||||
41 | Accepted | 134ms | 5552 KiB | ||||
42 | Accepted | 86ms | 5848 KiB |