#include <bits/stdc++.h>
using namespace std;
struct Data
{
int x1, y1, x2, y2;
Data() = default;
Data(int _x1, int _y1, int _x2, int _y2) : x1(_x1), y1(_y1), x2(_x2), y2(_y2) {}
};
const long long INF = 1e18;
int main()
{
cin.tie(0)->sync_with_stdio(0);
// freopen("in.in", "r", stdin);
// freopen("out.out", "w", stdout);
int M, n; cin >> M >> n;
vector<Data> a(n);
for (int i = 0; i < n; i++)
{
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
x1--, y1--;
a[i] = Data(x1, y1, x2, y2);
}
auto color = [&](int t, int K, int x, int y) -> int // 1 for black -1 for white
{
return (t + x / K + y / K) % 2 == 1 ? 1 : -1;
};
auto solve = [&](int K) -> long long
{
long long ret1 = (1ll * (M / K) * (M / K) / 2 + M / K % 2) * K * K;
for (auto &[x1, y1, x2, y2] : a)
{
int l1 = (x1 / K + (x1 % K > 0)) * K,
r1 = (x2 / K) * K,
l2 = (y1 / K + (y1 % K > 0)) * K,
r2 = (y2 / K) * K;
ret1 -= color(1, K, x1, y1) * (l1 - x1) * (l2 - y1);
if (color(1, K, l1, y1) != color(1, K, r1, y1))
ret1 -= color(1, K, l1, y1) * K * (l2 - y1);
ret1 -= color(1, K, r1, y1) * (x2 - r1) * (l2 - y1);
if (color(1, K, x1, l2) != color(1, K, x1, r2))
ret1 -= color(1, K, x1, l2) * (l1 - x1) * K;
if (color(1, K, l1, l2) != color(1, K, r1, l2) && color(1, K, l1, l2) != color(1, K, l1, r2))
ret1 -= color(1, K, l1, l2) * K * K;
if (color(1, K, r1, l2) != color(1, K, r1, r2))
ret1 -= color(1, K, r1, l2) * (x2 - r1) * K;
ret1 -= color(1, K, x1, r2) * (l1 - x1) * (y2 - r2);
if (color(1, K, l1, r2) != color(1, K, r1, r2))
ret1 -= color(1, K, l1, r2) * K * (y2 - r2);
ret1 -= color(1, K, r1, r2) * (x2 - r1) * (y2 - r2);
}
long long ret2 = (1ll * (M / K) * (M / K) / 2) * K * K;
for (auto &[x1, y1, x2, y2] : a)
{
int l1 = (x1 / K + (x1 % K > 0)) * K,
r1 = (x2 / K) * K,
l2 = (y1 / K + (y1 % K > 0)) * K,
r2 = (y2 / K) * K;
ret2 -= color(2, K, x1, y1) * (l1 - x1) * (l2 - y1);
if (color(2, K, l1, y1) != color(2, K, r1, y1))
ret2 -= color(2, K, l1, y1) * K * (l2 - y1);
ret2 -= color(2, K, r1, y1) * (x2 - r1) * (l2 - y1);
if (color(2, K, x1, l2) != color(2, K, x1, r2))
ret2 -= color(2, K, x1, l2) * (l1 - x1) * K;
if (color(2, K, l1, l2) != color(2, K, r1, l2) && color(2, K, l1, l2) != color(2, K, l1, r2))
ret2 -= color(2, K, l1, l2) * K * K;
if (color(2, K, r1, l2) != color(2, K, r1, r2))
ret2 -= color(2, K, r1, l2) * (x2 - r1) * K;
ret2 -= color(2, K, x1, r2) * (l1 - x1) * (y2 - r2);
if (color(2, K, l1, r2) != color(2, K, r1, r2))
ret2 -= color(2, K, l1, r2) * K * (y2 - r2);
ret2 -= color(2, K, r1, r2) * (x2 - r1) * (y2 - r2);
}
return min(ret1, ret2);
};
long long ans = INF;
for (int t = 1; t < M; t++)
if (M % t == 0)
ans = min(ans, solve(t));
cout << ans << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
600 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
1372 KB |
Output is correct |
2 |
Correct |
5 ms |
604 KB |
Output is correct |
3 |
Correct |
12 ms |
860 KB |
Output is correct |
4 |
Correct |
13 ms |
1116 KB |
Output is correct |
5 |
Correct |
18 ms |
1116 KB |
Output is correct |
6 |
Correct |
11 ms |
860 KB |
Output is correct |
7 |
Correct |
3 ms |
344 KB |
Output is correct |
8 |
Correct |
14 ms |
860 KB |
Output is correct |
9 |
Correct |
27 ms |
1628 KB |
Output is correct |
10 |
Correct |
15 ms |
1116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
596 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
412 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
596 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
412 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
10 ms |
860 KB |
Output is correct |
17 |
Correct |
22 ms |
1628 KB |
Output is correct |
18 |
Correct |
37 ms |
1884 KB |
Output is correct |
19 |
Correct |
154 ms |
1624 KB |
Output is correct |
20 |
Correct |
169 ms |
2136 KB |
Output is correct |
21 |
Correct |
20 ms |
1624 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
25 ms |
1116 KB |
Output is correct |
24 |
Correct |
33 ms |
1628 KB |
Output is correct |
25 |
Correct |
5 ms |
604 KB |
Output is correct |
26 |
Correct |
21 ms |
1116 KB |
Output is correct |
27 |
Correct |
35 ms |
1372 KB |
Output is correct |
28 |
Correct |
35 ms |
1884 KB |
Output is correct |
29 |
Correct |
8 ms |
860 KB |
Output is correct |
30 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
1372 KB |
Output is correct |
2 |
Correct |
5 ms |
604 KB |
Output is correct |
3 |
Correct |
12 ms |
860 KB |
Output is correct |
4 |
Correct |
13 ms |
1116 KB |
Output is correct |
5 |
Correct |
18 ms |
1116 KB |
Output is correct |
6 |
Correct |
11 ms |
860 KB |
Output is correct |
7 |
Correct |
3 ms |
344 KB |
Output is correct |
8 |
Correct |
14 ms |
860 KB |
Output is correct |
9 |
Correct |
27 ms |
1628 KB |
Output is correct |
10 |
Correct |
15 ms |
1116 KB |
Output is correct |
11 |
Correct |
1 ms |
596 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
412 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
344 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
10 ms |
860 KB |
Output is correct |
27 |
Correct |
22 ms |
1628 KB |
Output is correct |
28 |
Correct |
37 ms |
1884 KB |
Output is correct |
29 |
Correct |
154 ms |
1624 KB |
Output is correct |
30 |
Correct |
169 ms |
2136 KB |
Output is correct |
31 |
Correct |
20 ms |
1624 KB |
Output is correct |
32 |
Correct |
1 ms |
344 KB |
Output is correct |
33 |
Correct |
25 ms |
1116 KB |
Output is correct |
34 |
Correct |
33 ms |
1628 KB |
Output is correct |
35 |
Correct |
5 ms |
604 KB |
Output is correct |
36 |
Correct |
21 ms |
1116 KB |
Output is correct |
37 |
Correct |
35 ms |
1372 KB |
Output is correct |
38 |
Correct |
35 ms |
1884 KB |
Output is correct |
39 |
Correct |
8 ms |
860 KB |
Output is correct |
40 |
Correct |
1 ms |
344 KB |
Output is correct |
41 |
Incorrect |
130 ms |
1628 KB |
Output isn't correct |
42 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
600 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
18 ms |
1372 KB |
Output is correct |
10 |
Correct |
5 ms |
604 KB |
Output is correct |
11 |
Correct |
12 ms |
860 KB |
Output is correct |
12 |
Correct |
13 ms |
1116 KB |
Output is correct |
13 |
Correct |
18 ms |
1116 KB |
Output is correct |
14 |
Correct |
11 ms |
860 KB |
Output is correct |
15 |
Correct |
3 ms |
344 KB |
Output is correct |
16 |
Correct |
14 ms |
860 KB |
Output is correct |
17 |
Correct |
27 ms |
1628 KB |
Output is correct |
18 |
Correct |
15 ms |
1116 KB |
Output is correct |
19 |
Correct |
1 ms |
596 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
344 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
412 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
344 KB |
Output is correct |
33 |
Correct |
1 ms |
344 KB |
Output is correct |
34 |
Correct |
10 ms |
860 KB |
Output is correct |
35 |
Correct |
22 ms |
1628 KB |
Output is correct |
36 |
Correct |
37 ms |
1884 KB |
Output is correct |
37 |
Correct |
154 ms |
1624 KB |
Output is correct |
38 |
Correct |
169 ms |
2136 KB |
Output is correct |
39 |
Correct |
20 ms |
1624 KB |
Output is correct |
40 |
Correct |
1 ms |
344 KB |
Output is correct |
41 |
Correct |
25 ms |
1116 KB |
Output is correct |
42 |
Correct |
33 ms |
1628 KB |
Output is correct |
43 |
Correct |
5 ms |
604 KB |
Output is correct |
44 |
Correct |
21 ms |
1116 KB |
Output is correct |
45 |
Correct |
35 ms |
1372 KB |
Output is correct |
46 |
Correct |
35 ms |
1884 KB |
Output is correct |
47 |
Correct |
8 ms |
860 KB |
Output is correct |
48 |
Correct |
1 ms |
344 KB |
Output is correct |
49 |
Incorrect |
130 ms |
1628 KB |
Output isn't correct |
50 |
Halted |
0 ms |
0 KB |
- |