#include <bits/stdc++.h>
# define ll long long
# define fi first
# define se second
using namespace std;
const long long INF = 2e11;
const long long MOD = 1e9 + 7;
const long long N = 1e5 + 10;
const long long Z = 5e4 + 10;
ll n, k, ans = INF;
ll cor[N][4];
ll count(ll m)
{
ll ret1 = ((n / m) * (n / m) / 2 + (n / m) * (n / m) % 2) * m * m;
ll ret2 = ret1;
for (int i = 1; i <= k; i++){
ll r = cor[i][2] / m + (cor[i][2] % m != 0);
ll c = cor[i][3] / m + (cor[i][3] % m != 0);
if((c + r) % 2 == 0){
ret1--;
ret2++;
}
else{
ret1++;
ret2--;
}
}
return min(ret1, ret2);
}
void solve()
{
cin >> n >> k;
for (int i = 1 ; i <= k; i++)
for (int j = 0; j < 4; j++)cin >> cor[i][j];
for (int i = 1; i <= n; i++){
if(n % i != 0)
continue;
ans = min(ans, count((ll) i));
}
cout << ans;
}
int main()
{
int TE = 1;
ios_base::sync_with_stdio(false);
//freopen("photo.in", "r", stdin);
//freopen("photo.out", "w", stdout);
//cin >> TE;
while(TE --){
solve();
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
3904 KB |
Output is correct |
2 |
Incorrect |
11 ms |
3904 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
3904 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
3904 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
3904 KB |
Output is correct |
2 |
Incorrect |
11 ms |
3904 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |