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
#define pii pair<int, int>
#define oo 1e9
#define int ll
int n, k;
const int MAX = 1e5 + 5;
vector<pii> black;
vector<int> s;
void solve(){
cin >> n >> k;
for(int i = 1; i <= k; i++){
int a, b; cin >> a >> b >> a >> b;
black.push_back({a, b});
}
s.push_back(1);
for(int d = 2; d * d <= n; d++){
if(n % d == 0){
s.push_back(d);
if(n / d != d){
s.push_back(n / d);
}
}
}
int ans = oo;
for(int a : s){
int tmp1 = ((n / a) * (n / a) + 1) / 2 * a * a;
int tmp2 = ((n / a) * (n / a)) / 2 * a * a;
for(pii b : black){
int x = (b.first - 1) / a + 1;
int y = (b.second - 1) / a + 1;
if(x % 2 == y % 2){
tmp1--;
tmp2++;
}
else{
tmp1++;
tmp2--;
}
}
ans = min(tmp1, ans);
ans = min(tmp2, ans);
}
cout << ans << '\n';
}
signed main(){
int t = 1;
while(t--){
solve();
}
}
# | 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... |