10116 | 2024-03-27 00:13:59 | 111 | Játék a síkon | cpp17 | Time limit exceeded 10/100 | 600ms | 6592 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;
}
}
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()){
set<pair<int,int>>ss;
for(int i=0;i<N;i++){
if(!ss.insert({v[i].x,v[i].y}).second)exit(1);
}
}
}
cout<<ans.size()<<'\n';
for(int i:ans){
cout<<v[i].x<<' '<<v[i].y<<'\n';
}
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1888 KiB | ||||
2 | Time limit exceeded | 600ms | 1584 KiB | ||||
subtask2 | 0/9 | ||||||
3 | Wrong answer | 3ms | 2208 KiB | ||||
4 | Accepted | 3ms | 2336 KiB | ||||
subtask3 | 0/10 | ||||||
5 | Accepted | 3ms | 2548 KiB | ||||
6 | Accepted | 3ms | 2732 KiB | ||||
7 | Accepted | 3ms | 2836 KiB | ||||
8 | Wrong answer | 3ms | 3092 KiB | ||||
9 | Accepted | 3ms | 3160 KiB | ||||
10 | Accepted | 3ms | 3164 KiB | ||||
11 | Accepted | 3ms | 3392 KiB | ||||
12 | Wrong answer | 3ms | 3608 KiB | ||||
subtask4 | 10/10 | ||||||
13 | Accepted | 7ms | 3948 KiB | ||||
14 | Accepted | 7ms | 4096 KiB | ||||
15 | Accepted | 7ms | 4104 KiB | ||||
16 | Accepted | 8ms | 4364 KiB | ||||
subtask5 | 0/16 | ||||||
17 | Wrong answer | 10ms | 4524 KiB | ||||
18 | Accepted | 8ms | 4300 KiB | ||||
19 | Wrong answer | 8ms | 4676 KiB | ||||
20 | Wrong answer | 9ms | 4940 KiB | ||||
21 | Accepted | 25ms | 4808 KiB | ||||
subtask6 | 0/18 | ||||||
22 | Accepted | 7ms | 4792 KiB | ||||
23 | Wrong answer | 7ms | 5264 KiB | ||||
24 | Wrong answer | 7ms | 5096 KiB | ||||
25 | Wrong answer | 8ms | 5112 KiB | ||||
26 | Time limit exceeded | 566ms | 4020 KiB | ||||
subtask7 | 0/37 | ||||||
27 | Wrong answer | 92ms | 6592 KiB | ||||
28 | Accepted | 90ms | 5804 KiB | ||||
29 | Time limit exceeded | 564ms | 4984 KiB | ||||
30 | Time limit exceeded | 561ms | 5100 KiB | ||||
31 | Time limit exceeded | 527ms | 5068 KiB | ||||
32 | Time limit exceeded | 550ms | 4708 KiB | ||||
33 | Time limit exceeded | 578ms | 4460 KiB | ||||
34 | Time limit exceeded | 565ms | 4660 KiB | ||||
35 | Time limit exceeded | 561ms | 4644 KiB | ||||
36 | Time limit exceeded | 558ms | 5056 KiB | ||||
37 | Time limit exceeded | 550ms | 4988 KiB | ||||
38 | Time limit exceeded | 561ms | 4940 KiB | ||||
39 | Time limit exceeded | 560ms | 4988 KiB | ||||
40 | Time limit exceeded | 549ms | 5208 KiB | ||||
41 | Time limit exceeded | 564ms | 5196 KiB | ||||
42 | Time limit exceeded | 552ms | 4952 KiB |