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 N = 1e5 + 5;
const long long INF = 1e9 + 5;
const int MAXN = 1e6;
const int base = 317;
typedef long long ll;
const ll bs = 1e5 + 1;
const ll mod = 998244353;
int ans = INF, n, k, xx[N], yy[N];
int calc(int x) {
int res1 = 0, res2 = 0;
for (int i = 1; i <= k; i++) {
if ((xx[i] / x) % 2 == (yy[i] / x) % 2) {
res1++;
} else {
res2++;
}
}
int c1 = (n / x) * (n / x) / 2 * x * x;
int c2 = n * n - c1;
return min(c1 - res2 + res1, c2 - res1 + res2);
}
main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> k;
for (int i = 1; i <= k; i++) {
cin >> xx[i] >> yy[i] >> xx[i] >> yy[i];
xx[i]--;
yy[i]--;
}
for (int i = 1; i <= sqrt(n); i++) {
if (n % i == 0) {
ans = min(ans, calc(i));
if (i != 1)
ans = min(ans, calc(n / i));
}
}
cout << ans;
return 0;
}
/*
*/
Compilation message (stderr)
chessboard.cpp:31:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main() {
^
# | 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... |