#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
using ll = long long;
struct el {
ll a, b, c, d;
};
vector<ll> dv;
vector<el> points;
ll ans;
ll prefans(ll x, ll y, ll k, int f)
{
ll ans;
ll ab = y / k, a;
a = (ab + 1) / 2;
a *= k;
if (ab % 2 == 0)
a += y % k;
if (x <= k)
ans = x * a;
else
{
ll aa = y - a;
ll q = x / k;
ans = aa * (q / 2) * k;
ans += a * ((q + 1) / 2) * k;
if (q % 2)
ans += aa * (x % k);
else ans += a * (x % k);
}
if (f == 1)
return ans;
else return x * y - ans;
}
ll Paint(ll x, ll y, ll d, int f) {
return prefans(x, y, d, f) - (x * y - prefans(x, y, d, f));
}
int main()
{
ll n, k;
cin >> n >> k;
ans = n * n;
for (int i = 1; i < n; i++)
if (n % i == 0)dv.push_back(i);
for (int i = 0; i < k; i++)
{
ll a, b, c, d;
cin >> a >> b >> c >> d;
points.push_back({ a,b,c,d });
}/*
for (auto p : points)
cerr << p.first << ' ' << p.second << '\n';*/
for (ll d : dv)
{
ll blackans;
ll q = n / d;
if (q % 2)
blackans = (n * n - d * d) / 2 + d * d;
else blackans = n * n / 2;
ll whiteans = n * n - blackans;
for (auto p : points)
{
blackans += Paint(p.c, p.d, d, 0) - Paint(p.a - 1, p.d, d, 0) - Paint(p.c, p.b - 1, d, 0) + Paint(p.a - 1, p.b - 1, d, 0);
whiteans += Paint(p.c, p.d, d, 1) - Paint(p.a - 1, p.d, d, 1) - Paint(p.c, p.b - 1, d, 1) + Paint(p.a - 1, p.b - 1, d, 1);
}
ans = min(ans, min(blackans, whiteans));
}
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
0 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
83 ms |
2528 KB |
Output is correct |
2 |
Correct |
21 ms |
1508 KB |
Output is correct |
3 |
Correct |
53 ms |
2528 KB |
Output is correct |
4 |
Correct |
54 ms |
2528 KB |
Output is correct |
5 |
Correct |
80 ms |
2548 KB |
Output is correct |
6 |
Correct |
47 ms |
2528 KB |
Output is correct |
7 |
Correct |
10 ms |
748 KB |
Output is correct |
8 |
Correct |
47 ms |
2528 KB |
Output is correct |
9 |
Correct |
120 ms |
4724 KB |
Output is correct |
10 |
Correct |
67 ms |
2528 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
2 ms |
364 KB |
Output is correct |
5 |
Correct |
2 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
2 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
2 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
2 ms |
364 KB |
Output is correct |
14 |
Correct |
2 ms |
364 KB |
Output is correct |
15 |
Correct |
2 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
2 ms |
364 KB |
Output is correct |
5 |
Correct |
2 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
2 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
2 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
2 ms |
364 KB |
Output is correct |
14 |
Correct |
2 ms |
364 KB |
Output is correct |
15 |
Correct |
2 ms |
364 KB |
Output is correct |
16 |
Correct |
35 ms |
1508 KB |
Output is correct |
17 |
Correct |
91 ms |
4572 KB |
Output is correct |
18 |
Correct |
127 ms |
4572 KB |
Output is correct |
19 |
Correct |
321 ms |
4572 KB |
Output is correct |
20 |
Correct |
349 ms |
4572 KB |
Output is correct |
21 |
Correct |
90 ms |
4516 KB |
Output is correct |
22 |
Correct |
2 ms |
364 KB |
Output is correct |
23 |
Correct |
71 ms |
2684 KB |
Output is correct |
24 |
Correct |
114 ms |
4604 KB |
Output is correct |
25 |
Correct |
15 ms |
1000 KB |
Output is correct |
26 |
Correct |
71 ms |
2528 KB |
Output is correct |
27 |
Correct |
100 ms |
4572 KB |
Output is correct |
28 |
Correct |
125 ms |
4572 KB |
Output is correct |
29 |
Correct |
36 ms |
2528 KB |
Output is correct |
30 |
Correct |
4 ms |
492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
83 ms |
2528 KB |
Output is correct |
2 |
Correct |
21 ms |
1508 KB |
Output is correct |
3 |
Correct |
53 ms |
2528 KB |
Output is correct |
4 |
Correct |
54 ms |
2528 KB |
Output is correct |
5 |
Correct |
80 ms |
2548 KB |
Output is correct |
6 |
Correct |
47 ms |
2528 KB |
Output is correct |
7 |
Correct |
10 ms |
748 KB |
Output is correct |
8 |
Correct |
47 ms |
2528 KB |
Output is correct |
9 |
Correct |
120 ms |
4724 KB |
Output is correct |
10 |
Correct |
67 ms |
2528 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
2 ms |
364 KB |
Output is correct |
15 |
Correct |
2 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
2 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
2 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
2 ms |
364 KB |
Output is correct |
24 |
Correct |
2 ms |
364 KB |
Output is correct |
25 |
Correct |
2 ms |
364 KB |
Output is correct |
26 |
Correct |
35 ms |
1508 KB |
Output is correct |
27 |
Correct |
91 ms |
4572 KB |
Output is correct |
28 |
Correct |
127 ms |
4572 KB |
Output is correct |
29 |
Correct |
321 ms |
4572 KB |
Output is correct |
30 |
Correct |
349 ms |
4572 KB |
Output is correct |
31 |
Correct |
90 ms |
4516 KB |
Output is correct |
32 |
Correct |
2 ms |
364 KB |
Output is correct |
33 |
Correct |
71 ms |
2684 KB |
Output is correct |
34 |
Correct |
114 ms |
4604 KB |
Output is correct |
35 |
Correct |
15 ms |
1000 KB |
Output is correct |
36 |
Correct |
71 ms |
2528 KB |
Output is correct |
37 |
Correct |
100 ms |
4572 KB |
Output is correct |
38 |
Correct |
125 ms |
4572 KB |
Output is correct |
39 |
Correct |
36 ms |
2528 KB |
Output is correct |
40 |
Correct |
4 ms |
492 KB |
Output is correct |
41 |
Correct |
315 ms |
4572 KB |
Output is correct |
42 |
Correct |
147 ms |
4572 KB |
Output is correct |
43 |
Correct |
202 ms |
4712 KB |
Output is correct |
44 |
Correct |
141 ms |
4572 KB |
Output is correct |
45 |
Correct |
131 ms |
4572 KB |
Output is correct |
46 |
Correct |
342 ms |
4572 KB |
Output is correct |
47 |
Correct |
117 ms |
4624 KB |
Output is correct |
48 |
Correct |
175 ms |
4700 KB |
Output is correct |
49 |
Correct |
131 ms |
4700 KB |
Output is correct |
50 |
Correct |
1343 ms |
4572 KB |
Output is correct |
51 |
Correct |
1441 ms |
4572 KB |
Output is correct |
52 |
Correct |
1345 ms |
4700 KB |
Output is correct |
53 |
Correct |
1469 ms |
4572 KB |
Output is correct |
54 |
Correct |
1323 ms |
4720 KB |
Output is correct |
55 |
Correct |
1481 ms |
4572 KB |
Output is correct |
56 |
Correct |
1284 ms |
4572 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
0 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
364 KB |
Output is correct |
9 |
Correct |
83 ms |
2528 KB |
Output is correct |
10 |
Correct |
21 ms |
1508 KB |
Output is correct |
11 |
Correct |
53 ms |
2528 KB |
Output is correct |
12 |
Correct |
54 ms |
2528 KB |
Output is correct |
13 |
Correct |
80 ms |
2548 KB |
Output is correct |
14 |
Correct |
47 ms |
2528 KB |
Output is correct |
15 |
Correct |
10 ms |
748 KB |
Output is correct |
16 |
Correct |
47 ms |
2528 KB |
Output is correct |
17 |
Correct |
120 ms |
4724 KB |
Output is correct |
18 |
Correct |
67 ms |
2528 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
2 ms |
364 KB |
Output is correct |
23 |
Correct |
2 ms |
364 KB |
Output is correct |
24 |
Correct |
1 ms |
364 KB |
Output is correct |
25 |
Correct |
2 ms |
364 KB |
Output is correct |
26 |
Correct |
1 ms |
364 KB |
Output is correct |
27 |
Correct |
1 ms |
364 KB |
Output is correct |
28 |
Correct |
1 ms |
364 KB |
Output is correct |
29 |
Correct |
2 ms |
364 KB |
Output is correct |
30 |
Correct |
1 ms |
364 KB |
Output is correct |
31 |
Correct |
2 ms |
364 KB |
Output is correct |
32 |
Correct |
2 ms |
364 KB |
Output is correct |
33 |
Correct |
2 ms |
364 KB |
Output is correct |
34 |
Correct |
35 ms |
1508 KB |
Output is correct |
35 |
Correct |
91 ms |
4572 KB |
Output is correct |
36 |
Correct |
127 ms |
4572 KB |
Output is correct |
37 |
Correct |
321 ms |
4572 KB |
Output is correct |
38 |
Correct |
349 ms |
4572 KB |
Output is correct |
39 |
Correct |
90 ms |
4516 KB |
Output is correct |
40 |
Correct |
2 ms |
364 KB |
Output is correct |
41 |
Correct |
71 ms |
2684 KB |
Output is correct |
42 |
Correct |
114 ms |
4604 KB |
Output is correct |
43 |
Correct |
15 ms |
1000 KB |
Output is correct |
44 |
Correct |
71 ms |
2528 KB |
Output is correct |
45 |
Correct |
100 ms |
4572 KB |
Output is correct |
46 |
Correct |
125 ms |
4572 KB |
Output is correct |
47 |
Correct |
36 ms |
2528 KB |
Output is correct |
48 |
Correct |
4 ms |
492 KB |
Output is correct |
49 |
Correct |
315 ms |
4572 KB |
Output is correct |
50 |
Correct |
147 ms |
4572 KB |
Output is correct |
51 |
Correct |
202 ms |
4712 KB |
Output is correct |
52 |
Correct |
141 ms |
4572 KB |
Output is correct |
53 |
Correct |
131 ms |
4572 KB |
Output is correct |
54 |
Correct |
342 ms |
4572 KB |
Output is correct |
55 |
Correct |
117 ms |
4624 KB |
Output is correct |
56 |
Correct |
175 ms |
4700 KB |
Output is correct |
57 |
Correct |
131 ms |
4700 KB |
Output is correct |
58 |
Correct |
1343 ms |
4572 KB |
Output is correct |
59 |
Correct |
1441 ms |
4572 KB |
Output is correct |
60 |
Correct |
1345 ms |
4700 KB |
Output is correct |
61 |
Correct |
1469 ms |
4572 KB |
Output is correct |
62 |
Correct |
1323 ms |
4720 KB |
Output is correct |
63 |
Correct |
1481 ms |
4572 KB |
Output is correct |
64 |
Correct |
1284 ms |
4572 KB |
Output is correct |
65 |
Correct |
0 ms |
364 KB |
Output is correct |
66 |
Correct |
1 ms |
364 KB |
Output is correct |
67 |
Correct |
1387 ms |
4552 KB |
Output is correct |
68 |
Correct |
1393 ms |
4572 KB |
Output is correct |
69 |
Correct |
1255 ms |
4540 KB |
Output is correct |
70 |
Correct |
1375 ms |
4572 KB |
Output is correct |
71 |
Correct |
1346 ms |
4572 KB |
Output is correct |
72 |
Correct |
1334 ms |
4700 KB |
Output is correct |
73 |
Correct |
1270 ms |
4572 KB |
Output is correct |
74 |
Correct |
1354 ms |
4572 KB |
Output is correct |
75 |
Correct |
1355 ms |
4572 KB |
Output is correct |
76 |
Correct |
1425 ms |
4572 KB |
Output is correct |
77 |
Correct |
282 ms |
4572 KB |
Output is correct |
78 |
Correct |
138 ms |
4648 KB |
Output is correct |
79 |
Correct |
204 ms |
4628 KB |
Output is correct |
80 |
Correct |
220 ms |
4572 KB |
Output is correct |
81 |
Correct |
199 ms |
4700 KB |
Output is correct |
82 |
Correct |
186 ms |
4660 KB |
Output is correct |
83 |
Correct |
153 ms |
4700 KB |
Output is correct |
84 |
Correct |
855 ms |
4572 KB |
Output is correct |
85 |
Correct |
1430 ms |
4648 KB |
Output is correct |
86 |
Correct |
2 ms |
364 KB |
Output is correct |
87 |
Correct |
1 ms |
364 KB |
Output is correct |
88 |
Correct |
1507 ms |
4572 KB |
Output is correct |
89 |
Correct |
283 ms |
1508 KB |
Output is correct |
90 |
Correct |
1 ms |
364 KB |
Output is correct |