#include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define f first
#define s second
#define pii pair<ll,ll>
#define pll pair<ll,ll>
#define pb push_back
#define epb emplace_back
using namespace std;
/*
6 8
3 3 3 3
1 2 1 2
3 4 3 4
5 5 5 5
4 3 4 3
4 4 4 4
2 1 2 1
3 6 3 6
*/
ll C(ll x1, ll y1, ll x2, ll y2, ll a){
ll X = (x1 / a);
ll Y = (y1 / a);
if((X + Y) & 1) return 1;
return -1;
}
int main(){
// freopen("school.in", "r", stdin);
// freopen("school.out", "w", stdout);
ll n, k;
cin >> n >> k;
ll x1[k + 1], x2[k + 1], y1[k + 1], y2[k + 1];
for(int i = 1; i <= k; ++i){
cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
x1[i]--;
y1[i]--;
x2[i]--;
y2[i]--;
}
ll ans = 1e18 + 1;
for(int a = 1; a <n; a++){
if(n % a) continue;
ll v = n / a;
ll cnt = 0;
if(v % 2 == 1)
cnt += v * (v / 2) + (v + 1) / 2;
else cnt = v * v / 2;
cnt *= a * a;
for(int i = 1; i <= k; i++){
ll X = (x1[i] / a);
ll Y = (y1[i] / a);
if((X + Y) & 1) cnt++;
cnt--;
}
ans = min(ans, cnt);
}
for(ll a = 1; a <n; a++){
if(n % a) continue;
ll v = n / a;
ll cnt = -1;
if(v % 2 == 1)
cnt += v * (v / 2) + (v + 1) / 2;
else cnt = v * v / 2;
cnt *= a * a;
for(int i = 1; i <= k; i++){
ll X = (x1[i] / a);
ll Y = (y1[i] / a);
if((X + Y) & 1) cnt--;
cnt++;
}
ans = min(ans, cnt);
}
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
71 ms |
2232 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
71 ms |
2232 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Incorrect |
71 ms |
2232 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |