101142024-03-26 23:58:09111Játék a síkoncpp17Time limit exceeded 45/100600ms5580 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;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1824 KiB
2Time limit exceeded600ms2464 KiB
subtask29/9
3Accepted3ms2364 KiB
4Accepted3ms2536 KiB
subtask310/10
5Accepted3ms2556 KiB
6Accepted2ms2628 KiB
7Accepted3ms2764 KiB
8Accepted3ms2636 KiB
9Accepted3ms2632 KiB
10Accepted3ms2760 KiB
11Accepted3ms2968 KiB
12Accepted3ms3068 KiB
subtask410/10
13Accepted6ms3284 KiB
14Accepted7ms3696 KiB
15Accepted7ms3656 KiB
16Accepted8ms3920 KiB
subtask516/16
17Accepted10ms4252 KiB
18Accepted7ms4092 KiB
19Accepted8ms4080 KiB
20Accepted9ms4340 KiB
21Accepted25ms4316 KiB
subtask60/18
22Accepted6ms4304 KiB
23Accepted7ms4292 KiB
24Accepted7ms4260 KiB
25Accepted8ms4276 KiB
26Time limit exceeded565ms4496 KiB
subtask70/37
27Accepted90ms5484 KiB
28Accepted90ms5580 KiB
29Time limit exceeded555ms4556 KiB
30Time limit exceeded546ms4652 KiB
31Time limit exceeded573ms4716 KiB
32Time limit exceeded573ms4656 KiB
33Time limit exceeded577ms4080 KiB
34Time limit exceeded580ms4220 KiB
35Time limit exceeded541ms4308 KiB
36Time limit exceeded556ms4576 KiB
37Time limit exceeded564ms4632 KiB
38Time limit exceeded573ms4732 KiB
39Time limit exceeded564ms4672 KiB
40Time limit exceeded545ms4584 KiB
41Time limit exceeded554ms5004 KiB
42Time limit exceeded546ms4960 KiB