10114 | 2024-03-26 23:58:09 | 111 | Játék a síkon | cpp17 | Time limit exceeded 45/100 | 600ms | 5580 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;
}
}
if(1){
vector<int>ans1;
vector<vector<int>>g(N);
for(int i=0;i<N;i++){
for(int j=0;j<N;j++){
if(abs(v[j].x-v[i].x)+abs(v[j].y-v[i].y)==1){
g[i].push_back(j);
}
}
}
vector<int>w(N);
auto bt=[&](auto self,int i)->int{
if(w[i]){
return 1;
}
w[i]=1;
for(int j:g[i]){
if(!self(self,j)){
w[i]=0;
return 1;
}
}
w[i]=0;
return 0;
};
for(int i=0;i<N;i++){
if(!bt(bt,i)){
ans1.push_back(i);
}
}
if(ans.size()!=ans1.size()){
ans=ans1;
}
}
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 | Time limit exceeded | 600ms | 2464 KiB | ||||
subtask2 | 9/9 | ||||||
3 | Accepted | 3ms | 2364 KiB | ||||
4 | Accepted | 3ms | 2536 KiB | ||||
subtask3 | 10/10 | ||||||
5 | Accepted | 3ms | 2556 KiB | ||||
6 | Accepted | 2ms | 2628 KiB | ||||
7 | Accepted | 3ms | 2764 KiB | ||||
8 | Accepted | 3ms | 2636 KiB | ||||
9 | Accepted | 3ms | 2632 KiB | ||||
10 | Accepted | 3ms | 2760 KiB | ||||
11 | Accepted | 3ms | 2968 KiB | ||||
12 | Accepted | 3ms | 3068 KiB | ||||
subtask4 | 10/10 | ||||||
13 | Accepted | 6ms | 3284 KiB | ||||
14 | Accepted | 7ms | 3696 KiB | ||||
15 | Accepted | 7ms | 3656 KiB | ||||
16 | Accepted | 8ms | 3920 KiB | ||||
subtask5 | 16/16 | ||||||
17 | Accepted | 10ms | 4252 KiB | ||||
18 | Accepted | 7ms | 4092 KiB | ||||
19 | Accepted | 8ms | 4080 KiB | ||||
20 | Accepted | 9ms | 4340 KiB | ||||
21 | Accepted | 25ms | 4316 KiB | ||||
subtask6 | 0/18 | ||||||
22 | Accepted | 6ms | 4304 KiB | ||||
23 | Accepted | 7ms | 4292 KiB | ||||
24 | Accepted | 7ms | 4260 KiB | ||||
25 | Accepted | 8ms | 4276 KiB | ||||
26 | Time limit exceeded | 565ms | 4496 KiB | ||||
subtask7 | 0/37 | ||||||
27 | Accepted | 90ms | 5484 KiB | ||||
28 | Accepted | 90ms | 5580 KiB | ||||
29 | Time limit exceeded | 555ms | 4556 KiB | ||||
30 | Time limit exceeded | 546ms | 4652 KiB | ||||
31 | Time limit exceeded | 573ms | 4716 KiB | ||||
32 | Time limit exceeded | 573ms | 4656 KiB | ||||
33 | Time limit exceeded | 577ms | 4080 KiB | ||||
34 | Time limit exceeded | 580ms | 4220 KiB | ||||
35 | Time limit exceeded | 541ms | 4308 KiB | ||||
36 | Time limit exceeded | 556ms | 4576 KiB | ||||
37 | Time limit exceeded | 564ms | 4632 KiB | ||||
38 | Time limit exceeded | 573ms | 4732 KiB | ||||
39 | Time limit exceeded | 564ms | 4672 KiB | ||||
40 | Time limit exceeded | 545ms | 4584 KiB | ||||
41 | Time limit exceeded | 554ms | 5004 KiB | ||||
42 | Time limit exceeded | 546ms | 4960 KiB |