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 long long
const int NM = 1e5, inf = 1e18;
int N, K, x[NM+5], y[NM+5], ans = +inf;
int num[2];
void solve(int t){
num[0] = num[1] = 0;
for (int i = 1; i <= K; i++){
int blx = x[i]/t+(x[i]%t > 0), bly = y[i]/t+(y[i]%t > 0);
num[(blx+bly)%2]++;
}
int targ = t*t*(N*N/(t*t)/2);
cout << N << ' ' << t << ' ' << targ << endl;
ans = min(ans, abs(targ-num[0])+num[1]);
ans = min(ans, abs(targ-num[1])+num[0]);
ans = min(ans, abs(N*N-targ-num[0])+num[1]);
ans = min(ans, abs(N*N-targ-num[1])+num[0]);
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> N >> K;
for (int i = 1; i <= K; i++){
cin >> x[i] >> y[i] >> x[i] >> y[i];
}
for (int i = 1; i*i <= N; i++)
if (N%i == 0){
solve(i);
if (i > 1) solve(N/i);
}
cout << ans;
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... |