forked from ngthanhtrung23/CompetitiveProgramming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathC.cpp
More file actions
94 lines (76 loc) · 2.42 KB
/
C.cpp
File metadata and controls
94 lines (76 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; ++i)
#define FORD(i,a,b) for(int i=(a),_b=(b); i>=_b; --i)
#define REP(i,a) for(int i=0,_a=(a); i < _a; ++i)
#define DEBUG(X) { cout << #X << " = " << X << endl; }
#define PR(A,n) { cout << #A << " = "; FOR(_,1,n) cout << A[_] << ' '; cout << endl; }
#define PR0(A,n) { cout << #A << " = "; REP(_,n) cout << A[_] << ' '; cout << endl; }
#define ll long long
#define SZ(x) ((int) (x).size())
using namespace std;
const int MN = 200111;
int n, k;
pair<int,int> a[MN];
pair<int,int> allx[MN], ally[MN];
int inAllx[MN], inAlly[MN];
int minx, maxx, miny, maxy;
bool removed[MN];
pair<int,int> read() {
int x1, y1, x2, y2;
scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
return make_pair(x1 + x2, y1 + y2);
}
ll res;
void removeRect(int i) {
removed[i] = true;
while (removed[allx[minx].second]) ++minx;
while (removed[allx[maxx].second]) --maxx;
while (removed[ally[miny].second]) ++miny;
while (removed[ally[maxy].second]) --maxy;
}
void addRect(int i) {
removed[i] = false;
minx = min(minx, inAllx[i]);
miny = min(miny, inAlly[i]);
maxx = max(maxx, inAllx[i]);
maxy = max(maxy, inAlly[i]);
}
ll getArea() {
ll dx = allx[maxx].first - allx[minx].first; if (dx < 1) dx = 1; if (dx % 2) ++dx;
ll dy = ally[maxy].first - ally[miny].first; if (dy < 1) dy = 1; if (dy % 2) ++dy;
return dx * dy;
}
void solve(int i) {
if (i > k) {
res = min(res, getArea());
return ;
}
int u;
u = allx[minx].second;
removeRect(u); solve(i+1); addRect(u);
u = allx[maxx].second;
removeRect(u); solve(i+1); addRect(u);
u = ally[miny].second;
removeRect(u); solve(i+1); addRect(u);
u = ally[maxy].second;
removeRect(u); solve(i+1); addRect(u);
}
int main() {
while (scanf("%d%d", &n, &k) == 2) {
FOR(i,1,n) a[i] = read();
FOR(i,1,n) allx[i] = make_pair(a[i].first, i);
FOR(i,1,n) ally[i] = make_pair(a[i].second, i);
sort(allx+1, allx+n+1);
sort(ally+1, ally+n+1);
FOR(i,1,n) {
inAllx[allx[i].second] = i;
inAlly[ally[i].second] = i;
}
memset(removed, 0, sizeof removed);
minx = 1; maxx = n;
miny = 1; maxy = n;
res = getArea();
solve(1);
cout << res / 4 << endl;
}
}