101082024-03-26 22:35:01111Játék a síkoncpp17Wrong answer 10/100293ms5848 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';
	}
	return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1828 KiB
2Accepted8ms2264 KiB
subtask20/9
3Wrong answer3ms2252 KiB
4Accepted3ms2356 KiB
subtask30/10
5Accepted3ms2572 KiB
6Accepted3ms2656 KiB
7Accepted3ms2796 KiB
8Wrong answer3ms3012 KiB
9Accepted3ms3108 KiB
10Accepted3ms3352 KiB
11Accepted2ms3252 KiB
12Wrong answer3ms3256 KiB
subtask410/10
13Accepted4ms3464 KiB
14Accepted4ms3380 KiB
15Accepted4ms3520 KiB
16Accepted4ms3572 KiB
subtask50/16
17Wrong answer4ms3584 KiB
18Accepted4ms3696 KiB
19Wrong answer4ms3608 KiB
20Wrong answer4ms3632 KiB
21Accepted8ms3664 KiB
subtask60/18
22Accepted4ms3752 KiB
23Wrong answer4ms3792 KiB
24Wrong answer4ms3688 KiB
25Wrong answer4ms3840 KiB
26Wrong answer4ms3852 KiB
subtask70/37
27Wrong answer18ms4360 KiB
28Accepted18ms4396 KiB
29Accepted68ms4916 KiB
30Accepted293ms4880 KiB
31Accepted131ms4844 KiB
32Accepted21ms4824 KiB
33Accepted32ms4468 KiB
34Accepted54ms4492 KiB
35Accepted39ms4532 KiB
36Accepted24ms5060 KiB
37Accepted41ms5300 KiB
38Accepted26ms5340 KiB
39Accepted75ms5608 KiB
40Accepted83ms5460 KiB
41Accepted134ms5552 KiB
42Accepted86ms5848 KiB