10109 | 2024-03-26 22:37:48 | 111 | Játék a síkon | cpp17 | Wrong answer 10/100 | 384ms | 5904 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;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 2100 KiB | ||||
2 | Accepted | 8ms | 2552 KiB | ||||
subtask2 | 0/9 | ||||||
3 | Wrong answer | 2ms | 2396 KiB | ||||
4 | Accepted | 2ms | 2396 KiB | ||||
subtask3 | 0/10 | ||||||
5 | Accepted | 3ms | 2520 KiB | ||||
6 | Accepted | 2ms | 2512 KiB | ||||
7 | Accepted | 3ms | 2556 KiB | ||||
8 | Wrong answer | 3ms | 2772 KiB | ||||
9 | Accepted | 3ms | 3116 KiB | ||||
10 | Accepted | 3ms | 3260 KiB | ||||
11 | Accepted | 3ms | 3372 KiB | ||||
12 | Wrong answer | 3ms | 3412 KiB | ||||
subtask4 | 10/10 | ||||||
13 | Accepted | 4ms | 3836 KiB | ||||
14 | Accepted | 4ms | 4016 KiB | ||||
15 | Accepted | 4ms | 4232 KiB | ||||
16 | Accepted | 4ms | 4128 KiB | ||||
subtask5 | 0/16 | ||||||
17 | Wrong answer | 4ms | 4264 KiB | ||||
18 | Accepted | 4ms | 4512 KiB | ||||
19 | Wrong answer | 4ms | 4496 KiB | ||||
20 | Wrong answer | 4ms | 4504 KiB | ||||
21 | Accepted | 10ms | 4512 KiB | ||||
subtask6 | 0/18 | ||||||
22 | Accepted | 4ms | 4488 KiB | ||||
23 | Wrong answer | 4ms | 4468 KiB | ||||
24 | Wrong answer | 4ms | 4468 KiB | ||||
25 | Wrong answer | 4ms | 4592 KiB | ||||
26 | Wrong answer | 4ms | 4528 KiB | ||||
subtask7 | 0/37 | ||||||
27 | Wrong answer | 19ms | 5160 KiB | ||||
28 | Accepted | 18ms | 5156 KiB | ||||
29 | Accepted | 79ms | 5452 KiB | ||||
30 | Accepted | 384ms | 5492 KiB | ||||
31 | Accepted | 152ms | 5476 KiB | ||||
32 | Accepted | 23ms | 5600 KiB | ||||
33 | Accepted | 41ms | 4904 KiB | ||||
34 | Accepted | 67ms | 5116 KiB | ||||
35 | Accepted | 46ms | 5184 KiB | ||||
36 | Accepted | 25ms | 5828 KiB | ||||
37 | Accepted | 48ms | 5856 KiB | ||||
38 | Accepted | 27ms | 5824 KiB | ||||
39 | Accepted | 89ms | 5860 KiB | ||||
40 | Accepted | 97ms | 5808 KiB | ||||
41 | Accepted | 165ms | 5904 KiB | ||||
42 | Accepted | 101ms | 5804 KiB |