101092024-03-26 22:37:48111Játék a síkoncpp17Wrong answer 10/100384ms5904 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]=-1;
			if(!kuhn(g,b,x)){
				exit(1);
			}
		}
	}
	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]=-1;
			if(!kuhn(gg,bb,x)){
				exit(1);
			}
		}
	}
	cout<<ans.size()<<'\n';
	for(int i:ans){
		cout<<v[i].x<<' '<<v[i].y<<'\n';
	}
	return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms2100 KiB
2Accepted8ms2552 KiB
subtask20/9
3Wrong answer2ms2396 KiB
4Accepted2ms2396 KiB
subtask30/10
5Accepted3ms2520 KiB
6Accepted2ms2512 KiB
7Accepted3ms2556 KiB
8Wrong answer3ms2772 KiB
9Accepted3ms3116 KiB
10Accepted3ms3260 KiB
11Accepted3ms3372 KiB
12Wrong answer3ms3412 KiB
subtask410/10
13Accepted4ms3836 KiB
14Accepted4ms4016 KiB
15Accepted4ms4232 KiB
16Accepted4ms4128 KiB
subtask50/16
17Wrong answer4ms4264 KiB
18Accepted4ms4512 KiB
19Wrong answer4ms4496 KiB
20Wrong answer4ms4504 KiB
21Accepted10ms4512 KiB
subtask60/18
22Accepted4ms4488 KiB
23Wrong answer4ms4468 KiB
24Wrong answer4ms4468 KiB
25Wrong answer4ms4592 KiB
26Wrong answer4ms4528 KiB
subtask70/37
27Wrong answer19ms5160 KiB
28Accepted18ms5156 KiB
29Accepted79ms5452 KiB
30Accepted384ms5492 KiB
31Accepted152ms5476 KiB
32Accepted23ms5600 KiB
33Accepted41ms4904 KiB
34Accepted67ms5116 KiB
35Accepted46ms5184 KiB
36Accepted25ms5828 KiB
37Accepted48ms5856 KiB
38Accepted27ms5824 KiB
39Accepted89ms5860 KiB
40Accepted97ms5808 KiB
41Accepted165ms5904 KiB
42Accepted101ms5804 KiB