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;
#define ll long long
struct rect {
ll x1, y1, x2, y2;
};
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
vector<rect> a;
ll n, k;
cin >> n >> k;
for (int i = 0; i < k; i++) {
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
a.push_back({x1, y1, x2, y2});
}
ll res = n * n;
ll wh_cnt[n + 1], bl_cnt[n + 1];
for (int d = 1; d < n; d++) {
if (n % d) continue;
wh_cnt[0] = 0;
bl_cnt[0] = 0;
for (int i = 1; i <= n; i++) {
int id = (i + d - 1) / d;
wh_cnt[i] = wh_cnt[i - 1];
bl_cnt[i] = bl_cnt[i - 1];
if (id % 2) {
wh_cnt[i]++;
} else {
bl_cnt[i]++;
}
}
ll cur = (n / d) * (n / d) / 2 * d * d;
for (auto [x1, y1, x2, y2] : a) {
cur += (wh_cnt[x2] - wh_cnt[x1 - 1]) * (wh_cnt[y2] - wh_cnt[y1 - 1]) + (bl_cnt[x2] - bl_cnt[x1 - 1]) * (bl_cnt[y2] - bl_cnt[y1 - 1]);
cur -= (wh_cnt[x2] - wh_cnt[x1 - 1]) * (bl_cnt[y2] - bl_cnt[y1 - 1]) + (bl_cnt[x2] - bl_cnt[x1 - 1]) * (wh_cnt[y2] - wh_cnt[y1 - 1]);
}
res = min({res, cur, n * n - cur});
}
cout << res << '\n';
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... |