-
-
Notifications
You must be signed in to change notification settings - Fork 291
Expand file tree
/
Copy path223.cpp
More file actions
29 lines (27 loc) · 1.29 KB
/
223.cpp
File metadata and controls
29 lines (27 loc) · 1.29 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
__________________________________________________________________________________________________
sample 8 ms submission
auto gucciGang = []() {std::ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); return 0; }();
class Solution {
public:
int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) {
int s1 = (C - A) * (D - B);
int s2 = (G - E) * (H - F);
if (A >= G || E >= C || B >= H || F >= D) { return s1 + s2; }
else { return s1 - (min(C, G) - max(A, E)) * (min(D, H) - max(B, F)) + s2; }
}
};
__________________________________________________________________________________________________
sample 7980 kb submission
class Solution {
public:
int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) {
const long areaA = max((long)C - (long)A, 0L) * max((long)D - (long)B, 0L);
const long areaB = max((long)G - (long)E, 0L) * max((long)H - (long)F, 0L);
const int xBegin = max(A, E), xEnd = min(C, G);
const int yBegin = max(B, F), yEnd = min(D, H);
const int commonArea = (xBegin < xEnd && yBegin < yEnd) ?
(xEnd - xBegin) * (yEnd - yBegin) : 0;
return areaA + areaB - commonArea;
}
};
__________________________________________________________________________________________________