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;
const int MAXN = 1e5 + 5;
int n, k;
int xl[MAXN], xr[MAXN], yl[MAXN], yr[MAXN];
pair <int, int> Get(int p, int id)
{
if(p < 0)
{
return make_pair(0, 0);
}
int seg = p / id + 1;
int cw = (seg + 1) / 2, cb = seg / 2;
if(cw == cb)
{
return make_pair(cw * id, (cb - 1) * id + p % id + 1);
}
else
{
return make_pair((cw - 1) * id + p % id + 1, cb * id);
}
}
long long Solve(int id)
{
long long tmp = 1ll * (n / id) * (n / id) / 2;
long long curans = tmp * id * id;
for(int i = 1; i <= k; i++)
{
pair <int, int> AA = Get(xr[i], id), BB = Get(xl[i] - 1, id);
long long countxw = AA.first - BB.first, countxb = AA.second - BB.second;
AA = Get(yr[i], id), BB = Get(yl[i] - 1, id);
long long countyw = AA.first - BB.first, countyb = AA.second - BB.second;
long long corr = countyw * countxb + countyb * countxw, incorr = countyb * countxb + countyw * countxw;
curans -= corr;
curans += incorr;
}
return min(curans, 1ll * n * n - curans);
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> k;
for(int i = 1; i <= k; i++)
{
cin >> xl[i] >> yl[i] >> xr[i] >> yr[i];
xl[i]--;
yl[i]--;
xr[i]--;
yr[i]--;
}
long long ans = 1e18;
for(int i = 1; i < n; i++)
{
if(n % i == 0)
{
ans = min(ans, Solve(i));
}
}
cout << ans << '\n';
}
# | 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... |