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 int int64_t
int32_t main() {
int N, K; cin >> N >> K;
int ans = N * N;
array<int, 4> a[K];
for(auto &[i, j, k, l] : a)
cin >> i >> j >> k >> l;
for(int s = 1; s < N; ++s) if(!(N % s)) {
#define c(V) (s * ((V) / (2 * s)) + min(s, (V) % (2 * s)))
int cost = c(N) * (N - c(N)) + c(N) * (N - c(N));
for(auto [i, j, k, l] : a) {
int u = k - i + 1, x = c(k) - c(i - 1);
int v = l - j + 1, y = c(l) - c(j - 1);
cost += 2 * (x * y + (u - x) * (v - y)) - u * v;
}
ans = min(ans, min(cost, N * N - cost));
}
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... |