101102024-03-26 22:52:59111Játék a síkoncpp17Wrong answer 0/100575ms6224 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 x) {
	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;
	};
	for (int i = 0; i < g.size(); i++) {
		if (dfs(dfs, i)) {
			return true;
		}
	}
	return false;
}

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
1Accepted3ms1824 KiB
2Wrong answer25ms2252 KiB
subtask20/9
3Wrong answer3ms2228 KiB
4Accepted3ms2440 KiB
subtask30/10
5Accepted3ms2660 KiB
6Accepted3ms2872 KiB
7Accepted3ms2956 KiB
8Wrong answer3ms3080 KiB
9Accepted3ms3164 KiB
10Wrong answer3ms3296 KiB
11Wrong answer3ms3392 KiB
12Wrong answer3ms3528 KiB
subtask40/10
13Accepted4ms3916 KiB
14Wrong answer12ms3944 KiB
15Wrong answer17ms3944 KiB
16Wrong answer16ms3952 KiB
subtask50/16
17Wrong answer14ms4156 KiB
18Wrong answer17ms4240 KiB
19Wrong answer10ms4228 KiB
20Wrong answer10ms4224 KiB
21Accepted18ms4472 KiB
subtask60/18
22Accepted4ms4296 KiB
23Wrong answer13ms4568 KiB
24Wrong answer12ms4784 KiB
25Wrong answer14ms4744 KiB
26Wrong answer16ms4884 KiB
subtask70/37
27Wrong answer137ms5372 KiB
28Accepted64ms5588 KiB
29Time limit exceeded568ms4832 KiB
30Time limit exceeded526ms4764 KiB
31Time limit exceeded575ms6156 KiB
32Wrong answer490ms5804 KiB
33Wrong answer92ms5308 KiB
34Wrong answer92ms5308 KiB
35Wrong answer92ms5556 KiB
36Time limit exceeded566ms4880 KiB
37Time limit exceeded564ms5008 KiB
38Time limit exceeded565ms4964 KiB
39Time limit exceeded570ms6224 KiB
40Time limit exceeded556ms4960 KiB
41Time limit exceeded558ms4960 KiB
42Time limit exceeded565ms4960 KiB