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;
template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl
using ll = long long;
const ll inf = 1e18;
ll n,k;
vector<pair<ll,ll>> a;
ll solve(ll x) {
map<ll,ll> dp;
for (auto p: a) {
dp[(p.first/x + p.second/x)%2]++;
}
ll res = inf;
ll cells = (n/x)*(n/x);
ll area = x*x;
//even black
{
ll sq = (cells/2 + (n/x)%2);
ll cur = (sq*area - dp[0]) + dp[1];
res = min(res, cur);
}
//odd black
{
ll sq = cells/2;
ll cur = (sq*area - dp[1]) + dp[0];
res = min(res, cur);
}
return res;
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin>>n>>k;
a.resize(k);
for (int i=0; i<k; i++) {
cin>>a[i].first>>a[i].second;
cin>>a[i].first>>a[i].second;
--a[i].first; --a[i].second;
}
ll res = inf;
for (ll i=1; i<n; i++) {
if (n%i==0) {
ll cur=solve(i);
//cout<<i<<": "<<cur<<endl;
res = min(res, cur);
}
}
cout<<res<<endl;
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... |