10110 | 2024-03-26 22:52:59 | 111 | Játék a síkon | cpp17 | Wrong answer 0/100 | 575ms | 6224 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;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1824 KiB | ||||
2 | Wrong answer | 25ms | 2252 KiB | ||||
subtask2 | 0/9 | ||||||
3 | Wrong answer | 3ms | 2228 KiB | ||||
4 | Accepted | 3ms | 2440 KiB | ||||
subtask3 | 0/10 | ||||||
5 | Accepted | 3ms | 2660 KiB | ||||
6 | Accepted | 3ms | 2872 KiB | ||||
7 | Accepted | 3ms | 2956 KiB | ||||
8 | Wrong answer | 3ms | 3080 KiB | ||||
9 | Accepted | 3ms | 3164 KiB | ||||
10 | Wrong answer | 3ms | 3296 KiB | ||||
11 | Wrong answer | 3ms | 3392 KiB | ||||
12 | Wrong answer | 3ms | 3528 KiB | ||||
subtask4 | 0/10 | ||||||
13 | Accepted | 4ms | 3916 KiB | ||||
14 | Wrong answer | 12ms | 3944 KiB | ||||
15 | Wrong answer | 17ms | 3944 KiB | ||||
16 | Wrong answer | 16ms | 3952 KiB | ||||
subtask5 | 0/16 | ||||||
17 | Wrong answer | 14ms | 4156 KiB | ||||
18 | Wrong answer | 17ms | 4240 KiB | ||||
19 | Wrong answer | 10ms | 4228 KiB | ||||
20 | Wrong answer | 10ms | 4224 KiB | ||||
21 | Accepted | 18ms | 4472 KiB | ||||
subtask6 | 0/18 | ||||||
22 | Accepted | 4ms | 4296 KiB | ||||
23 | Wrong answer | 13ms | 4568 KiB | ||||
24 | Wrong answer | 12ms | 4784 KiB | ||||
25 | Wrong answer | 14ms | 4744 KiB | ||||
26 | Wrong answer | 16ms | 4884 KiB | ||||
subtask7 | 0/37 | ||||||
27 | Wrong answer | 137ms | 5372 KiB | ||||
28 | Accepted | 64ms | 5588 KiB | ||||
29 | Time limit exceeded | 568ms | 4832 KiB | ||||
30 | Time limit exceeded | 526ms | 4764 KiB | ||||
31 | Time limit exceeded | 575ms | 6156 KiB | ||||
32 | Wrong answer | 490ms | 5804 KiB | ||||
33 | Wrong answer | 92ms | 5308 KiB | ||||
34 | Wrong answer | 92ms | 5308 KiB | ||||
35 | Wrong answer | 92ms | 5556 KiB | ||||
36 | Time limit exceeded | 566ms | 4880 KiB | ||||
37 | Time limit exceeded | 564ms | 5008 KiB | ||||
38 | Time limit exceeded | 565ms | 4964 KiB | ||||
39 | Time limit exceeded | 570ms | 6224 KiB | ||||
40 | Time limit exceeded | 556ms | 4960 KiB | ||||
41 | Time limit exceeded | 558ms | 4960 KiB | ||||
42 | Time limit exceeded | 565ms | 4960 KiB |