101132024-03-26 23:57:29111Játék a síkoncpp17Time limit exceeded 10/100598ms5028 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';
	}
	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()){
			exit(1);
		}
	}
	return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1864 KiB
2Time limit exceeded598ms2560 KiB
subtask20/9
3Runtime error3ms2140 KiB
4Accepted3ms2340 KiB
subtask30/10
5Accepted3ms2424 KiB
6Accepted2ms2432 KiB
7Accepted3ms2436 KiB
8Runtime error3ms2444 KiB
9Accepted3ms2568 KiB
10Accepted3ms2776 KiB
11Accepted3ms2860 KiB
12Runtime error3ms2928 KiB
subtask410/10
13Accepted7ms3156 KiB
14Accepted7ms3204 KiB
15Accepted7ms3216 KiB
16Accepted8ms3476 KiB
subtask50/16
17Runtime error10ms3448 KiB
18Accepted8ms3616 KiB
19Runtime error8ms3672 KiB
20Runtime error9ms3680 KiB
21Accepted25ms3592 KiB
subtask60/18
22Accepted7ms3652 KiB
23Runtime error7ms3788 KiB
24Runtime error7ms4116 KiB
25Runtime error8ms4004 KiB
26Time limit exceeded577ms4200 KiB
subtask70/37
27Runtime error93ms5028 KiB
28Accepted92ms4732 KiB
29Time limit exceeded559ms3864 KiB
30Time limit exceeded560ms3916 KiB
31Time limit exceeded541ms3972 KiB
32Time limit exceeded561ms4244 KiB
33Time limit exceeded558ms3712 KiB
34Time limit exceeded584ms3772 KiB
35Time limit exceeded552ms3716 KiB
36Time limit exceeded582ms4064 KiB
37Time limit exceeded577ms4124 KiB
38Time limit exceeded573ms4100 KiB
39Time limit exceeded560ms4148 KiB
40Time limit exceeded569ms4108 KiB
41Time limit exceeded580ms4116 KiB
42Time limit exceeded569ms4108 KiB