101162024-03-27 00:13:59111Játék a síkoncpp17Time limit exceeded 10/100600ms6592 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()){
			set<pair<int,int>>ss;
			for(int i=0;i<N;i++){
				if(!ss.insert({v[i].x,v[i].y}).second)exit(1);
			}
		}
	}
	cout<<ans.size()<<'\n';
	for(int i:ans){
		cout<<v[i].x<<' '<<v[i].y<<'\n';
	}
	return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1888 KiB
2Time limit exceeded600ms1584 KiB
subtask20/9
3Wrong answer3ms2208 KiB
4Accepted3ms2336 KiB
subtask30/10
5Accepted3ms2548 KiB
6Accepted3ms2732 KiB
7Accepted3ms2836 KiB
8Wrong answer3ms3092 KiB
9Accepted3ms3160 KiB
10Accepted3ms3164 KiB
11Accepted3ms3392 KiB
12Wrong answer3ms3608 KiB
subtask410/10
13Accepted7ms3948 KiB
14Accepted7ms4096 KiB
15Accepted7ms4104 KiB
16Accepted8ms4364 KiB
subtask50/16
17Wrong answer10ms4524 KiB
18Accepted8ms4300 KiB
19Wrong answer8ms4676 KiB
20Wrong answer9ms4940 KiB
21Accepted25ms4808 KiB
subtask60/18
22Accepted7ms4792 KiB
23Wrong answer7ms5264 KiB
24Wrong answer7ms5096 KiB
25Wrong answer8ms5112 KiB
26Time limit exceeded566ms4020 KiB
subtask70/37
27Wrong answer92ms6592 KiB
28Accepted90ms5804 KiB
29Time limit exceeded564ms4984 KiB
30Time limit exceeded561ms5100 KiB
31Time limit exceeded527ms5068 KiB
32Time limit exceeded550ms4708 KiB
33Time limit exceeded578ms4460 KiB
34Time limit exceeded565ms4660 KiB
35Time limit exceeded561ms4644 KiB
36Time limit exceeded558ms5056 KiB
37Time limit exceeded550ms4988 KiB
38Time limit exceeded561ms4940 KiB
39Time limit exceeded560ms4988 KiB
40Time limit exceeded549ms5208 KiB
41Time limit exceeded564ms5196 KiB
42Time limit exceeded552ms4952 KiB