This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
auto calc = [&](int i, int l) {
return i / (2 * l) * l + min(l, i % (2 * l));
};
int n, k; cin >> n >> k;
vector<array<int, 4>> rect(k);
for (int i = 0; i < k; ++i) {
for (int j = 0; j < 4; ++j) {
cin >> rect[i][j];
}
}
long long res = (long long) n * n;
for (int l = 1; l < n; ++l) {
if (n % l == 0) {
long long x = 2LL * calc(n, l) * (n - calc(n, l));
for (auto [r1, c1, r2, c2] : rect) {
int r = calc(r2, l) - calc(r1 - 1, l), c = calc(c2, l) - calc(c1 - 1, l);
int cr = r2 - r1 + 1, cc = c2 - c1 + 1;
x += 2LL * r * c + 2LL * (cr - r) * (cc - c) - (long long) cr * cc;
}
res = min({res, x, (long long) n * n - x});
}
}
cout << res;
return 0;
}
# | 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... |