10115 | 2024-03-27 00:09:44 | 111 | Játék a síkon | cpp17 | Time limit exceeded 10/100 | 600ms | 5308 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()){
exit(ans.size()<ans1.size());
}
}
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 | 1828 KiB | ||||
2 | Time limit exceeded | 600ms | 1580 KiB | ||||
subtask2 | 0/9 | ||||||
3 | Wrong answer | 3ms | 2328 KiB | ||||
4 | Accepted | 3ms | 2444 KiB | ||||
subtask3 | 0/10 | ||||||
5 | Accepted | 3ms | 2656 KiB | ||||
6 | Accepted | 3ms | 2868 KiB | ||||
7 | Accepted | 3ms | 2868 KiB | ||||
8 | Runtime error | 3ms | 2884 KiB | ||||
9 | Accepted | 3ms | 2980 KiB | ||||
10 | Accepted | 3ms | 3108 KiB | ||||
11 | Accepted | 3ms | 3208 KiB | ||||
12 | Wrong answer | 3ms | 3424 KiB | ||||
subtask4 | 10/10 | ||||||
13 | Accepted | 7ms | 3708 KiB | ||||
14 | Accepted | 7ms | 3748 KiB | ||||
15 | Accepted | 7ms | 3764 KiB | ||||
16 | Accepted | 8ms | 3764 KiB | ||||
subtask5 | 0/16 | ||||||
17 | Wrong answer | 10ms | 4028 KiB | ||||
18 | Accepted | 8ms | 4088 KiB | ||||
19 | Wrong answer | 8ms | 4200 KiB | ||||
20 | Wrong answer | 9ms | 4292 KiB | ||||
21 | Accepted | 25ms | 4384 KiB | ||||
subtask6 | 0/18 | ||||||
22 | Accepted | 7ms | 4132 KiB | ||||
23 | Wrong answer | 7ms | 4180 KiB | ||||
24 | Wrong answer | 7ms | 4516 KiB | ||||
25 | Wrong answer | 8ms | 4484 KiB | ||||
26 | Time limit exceeded | 546ms | 4464 KiB | ||||
subtask7 | 0/37 | ||||||
27 | Wrong answer | 90ms | 5308 KiB | ||||
28 | Accepted | 90ms | 5144 KiB | ||||
29 | Time limit exceeded | 564ms | 4152 KiB | ||||
30 | Time limit exceeded | 578ms | 4428 KiB | ||||
31 | Time limit exceeded | 546ms | 4388 KiB | ||||
32 | Time limit exceeded | 569ms | 4360 KiB | ||||
33 | Time limit exceeded | 565ms | 3904 KiB | ||||
34 | Time limit exceeded | 578ms | 3980 KiB | ||||
35 | Time limit exceeded | 565ms | 4240 KiB | ||||
36 | Time limit exceeded | 583ms | 4604 KiB | ||||
37 | Time limit exceeded | 550ms | 4660 KiB | ||||
38 | Time limit exceeded | 565ms | 4676 KiB | ||||
39 | Time limit exceeded | 554ms | 4580 KiB | ||||
40 | Time limit exceeded | 549ms | 4792 KiB | ||||
41 | Time limit exceeded | 560ms | 4920 KiB | ||||
42 | Time limit exceeded | 569ms | 4620 KiB |