#include <iostream>
#include<vector>
#include<set>
const int inf = 1e9;
using namespace std;
int n, m, d;
int solve(int x, int y, vector<pair<int, int>>& a, vector<pair<int, int>>& b) {
vector<vector<vector<int>>> g(d + 1, vector<vector<int>>(d + 1, vector<int>(0)));
int al = d, ar = 0, au = n, ad = 0;
//o(d^2*(n+m)) To Be Optimized to o(d^2*m)
for (int i = 0; i < (d + 1); ++i)
for (int j = 0; j < (d + 1); ++j) {
for (int k = 0; k < n; ++k) if ((((i + x) % d) == (a[k].first % d))
&& (((j + y) % d) == (a[k].second % d))) g[i][j].push_back(k),
al = min(al, j), ar = max(ar, j), au = min(au, i), ad = max(ad, i);
for (int k = 0; k < m; ++k) if ((((i + x) % d) == (b[k].first % d))
|| (((j + y) % d) == (b[k].second % d))) g[i][j].push_back(k + n);
}
//o(d^2*m)
int ans = inf;
for (int si = 0; si <= au; ++si)
for (int ei = max(si, ad); ei <= d; ++ei) {
//row si to row di
int sj = al, ej = ar;
for (auto o : b) {
int r = o.first % d;
while (r < si) r += d;
if (r > ei) {
int c = o.second % d;
while (c < y) c += d;
sj = min(sj, c), ej = max(ej, c);
}
}
int cur = (ej - sj + 1) * (ei - si + 1);
ans = min(ans, cur);
}
return ans;
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
cin >> n >> m >> d;
vector<pair<int, int>> a(n);
vector<pair<int, int>> b(m);
for (auto& x : a) cin >> x.first >> x.second;
for (auto& x : b) cin >> x.first >> x.second;
int ans = inf;
ans = min(ans, solve(0, 0, a, b));
ans = min(ans, solve(d, d, a, b));
for (int x = max(0, d / 2 - 2); x <= (d / 2 + 2); ++x)
for (int y = max(0, d / 2 - 2); y <= (d / 2 + 2); ++y)
ans = min(ans, solve(x, y, a, b));
cout << ans;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |