-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRectangle Partition.cpp
More file actions
40 lines (32 loc) · 972 Bytes
/
Rectangle Partition.cpp
File metadata and controls
40 lines (32 loc) · 972 Bytes
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
#include <iostream>
#include <vector>
using namespace std;
int main()
{
int w, h, count_x, count_y;
cin >> w >> h >> count_x >> count_y;
vector<int> X(count_x + 2), Y(count_y + 2);
X[0] = 0;
for (int i = 1; i <= count_x; i++) cin >> X[i];
X[count_x + 1] = w;
Y[0] = 0;
for (int i = 1; i <= count_y; i++) cin >> Y[i];
Y[count_y + 1] = h;
int maxLen = max(w, h);
vector<long long> freqX(maxLen + 1, 0), freqY(maxLen + 1, 0);
for (int i = 0; i < (int)X.size(); i++) {
for (int j = i + 1; j < (int)X.size(); j++) {
freqX[X[j] - X[i]]++;
}
}
for (int i = 0; i < (int)Y.size(); i++) {
for (int j = i + 1; j < (int)Y.size(); j++) {
freqY[Y[j] - Y[i]]++;
}
}
long long result = 0;
for (int len = 1; len <= min(w, h); len++) {
result += freqX[len] * freqY[len];
}
cout << result << endl;
}