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
vector <ll> p;
ll f(ll x1, ll y1, ll x2, ll y2){
ll z = (p[y2] - p[y1-1]);
z *= (p[x2] - p[x1-1]);
z += (((x2-x1+1) - (p[x2] - p[x1-1])) * ((y2-y1+1) - (p[y2] - p[y1-1])));
return z;
}
int main(){
ios::sync_with_stdio(false); cin.tie(nullptr);
ll n, k, k1 = 0;
cin >> n >> k;
vector <int> x1(k+1), y1(k+1), x2(k+1), y2(k+1);
for(int i = 1; i <= k; i++){
cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
ll a = (x2[i] - x1[i] + 1), b = (y2[i] - y1[i] + 1);
a *= b;
k1 += a;
}
ll ans = n, n1 = n;
ans *= n;
n1 *= n;
// cout << k1 << "\n";
for(ll x3 = 1; x3 < n; x3++){
if(n % x3 != 0) continue;
p.assign(n+2,0);
ll x = (x3 * 2), cnt = 0;
for(int i = 1; i <= n; i++){
p[i] = p[i-1] + ((i % x) <= (x / 2) and (i % x) != 0);
}
for(int i = 1; i <= k; i++){
cnt += f(x1[i], y1[i], x2[i], y2[i]);
}
// cout << x3 << ' ' << cnt << "\n";
ll y = ((x3 * x3) * (((n / x3) + 1) / 2) * (((n / x3) + 1) / 2)) + ((x3 * x3) * ((n / x3) / 2) * ((n / x3) / 2));
ans = min(ans, (y - cnt + (k1-cnt)));
ans = min(ans, (n1 - y) - (k1-cnt) + cnt);
}
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... |