This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//-------------dilanyan------------\\
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
//------------------KarginDefines--------------------\\
#define ll long long
#define pb push_back
#define all(u) (u).begin(), (u).end()
#define pqueue priority_queue
#define upper upper_bound
#define lower lower_bound
#define umap unordered_map
#define uset unordered_set
#define Kargin ios_base::sync_with_stdio(false);cin.tie(NULL);
#define Usaco freopen(".in", "r", stdin); freopen(".out", "w", stdout);
//-------------------KarginConstants------------------\\
const ll mod = 1000000007;
const ll inf = 1e9 + 15;
//-------------------KarginCode------------------------\\
const int N = 100005;
ll x[N], y[N];
void KarginSolve() {
ll n, k;
cin >> n >> k;
ll sq = sqrt(n);
vector<ll> div;
for (ll i = 1;i <= sq;i++) {
if (n % i == 0) {
div.pb(i);
if (i * i != n) div.pb(n / i);
}
}
for (int i = 0;i < k;i++) cin >> x[i] >> y[i] >> x[i] >> y[i];
ll ans = inf;
for (ll d : div) {
if (d == n) continue;
ll c = (n * n) / (d * d);
ll fw = c / 2, fb = (c + 1) / 2;
fw *= d * d, fb *= d * d;
for (int i = 0;i < k;i++) {
int dx = (x[i] + d - 1) / d, dy = (y[i] + d - 1) / d;
if (dx & 1) {
if (dy & 1) fw++, fb--;
else fw--, fb++;
}
else {
if (dy & 1) fw--, fb++;
else fw++, fb--;
}
}
ans = min(ans, min(fw, fb));
}
cout << ans << '\n';
}
int main() {
//Usaco
Kargin;
int test = 1;
//cin >> test;
while (test--) {
KarginSolve();
}
return 0;
}
Compilation message (stderr)
chessboard.cpp:1:1: warning: multi-line comment [-Wcomment]
1 | //-------------dilanyan------------\\
| ^
chessboard.cpp:8:1: warning: multi-line comment [-Wcomment]
8 | //------------------KarginDefines--------------------\\
| ^
chessboard.cpp:22:1: warning: multi-line comment [-Wcomment]
22 | //-------------------KarginConstants------------------\\
| ^
chessboard.cpp:27:1: warning: multi-line comment [-Wcomment]
27 | //-------------------KarginCode------------------------\\
| ^
# | 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... |