101172024-03-27 11:33:06111Játék a síkoncpp17Accepted 100/100293ms6488 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&1)==(p.y&1);})-v.begin(); // -5 % 2 = -1
	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;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1824 KiB
2Accepted7ms2276 KiB
subtask29/9
3Accepted3ms2264 KiB
4Accepted3ms2480 KiB
subtask310/10
5Accepted3ms2588 KiB
6Accepted3ms2668 KiB
7Accepted3ms2808 KiB
8Accepted3ms3040 KiB
9Accepted3ms3108 KiB
10Accepted3ms3240 KiB
11Accepted3ms3332 KiB
12Accepted3ms3456 KiB
subtask410/10
13Accepted4ms3656 KiB
14Accepted4ms3844 KiB
15Accepted4ms4064 KiB
16Accepted4ms4212 KiB
subtask516/16
17Accepted4ms4308 KiB
18Accepted4ms4376 KiB
19Accepted4ms4380 KiB
20Accepted4ms4512 KiB
21Accepted8ms4660 KiB
subtask618/18
22Accepted4ms4632 KiB
23Accepted4ms4556 KiB
24Accepted4ms4568 KiB
25Accepted4ms4584 KiB
26Accepted4ms4700 KiB
subtask737/37
27Accepted20ms5312 KiB
28Accepted19ms5328 KiB
29Accepted68ms5680 KiB
30Accepted293ms5756 KiB
31Accepted131ms5780 KiB
32Accepted21ms5764 KiB
33Accepted32ms5344 KiB
34Accepted54ms5352 KiB
35Accepted39ms5368 KiB
36Accepted24ms6008 KiB
37Accepted41ms6244 KiB
38Accepted26ms6204 KiB
39Accepted75ms6332 KiB
40Accepted83ms6384 KiB
41Accepted134ms6452 KiB
42Accepted86ms6488 KiB