#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;
bool get_color(pair<int, int> p, int d) {
return (p.first / d + p.second / d) & 1;
}
ll intersect(pair<pair<int, int>, pair<int, int>> r1, pair<pair<int, int>, pair<int, int>> r2) {
ll w = min(r1.second.first, r2.second.first) - max(r1.first.first, r2.first.first);
ll h = min(r1.second.second, r2.second.second) - max(r1.first.second, r2.first.second);
if (w < 0 || h < 0)
return 0;
return w * h;
}
signed main() {
ll n, k;
cin >> n >> k;
vector<pair<pair<int, int>, pair<int, int>>> rect(k);
for (int i = 0; i < k; ++i) {
cin >> rect[i].first.first >> rect[i].first.second >> rect[i].second.first >> rect[i].second.second;
--rect[i].first.first, --rect[i].first.second, --rect[i].second.first, --rect[i].second.second;
}
vector<ll> divs;
for (int p = 1; p < n; ++p) {
if (n % p == 0)
divs.push_back(p);
}
int szd = divs.size();
vector<ll> ans(szd);
for (int di = 0; di < szd; ++di) {
ll d = divs[di];
if (n / d == 0)
ans[di] = n * n / 2;
else
ans[di] = d * d * ((n / d) * (n / d) / 2);
}
for (auto [ld, ru] : rect) {
for (int di = 0; di < szd; ++di) {
ll d = divs[di];
int r = ld.first + (ru.first - ld.first) % (2 * d);
int u = ld.second + (ru.second - ld.second) % (2 * d);
pair<pair<int, int>, pair<int, int>> rct = {ld, {r + 1, u + 1}};
ll bi = ld.first / (2 * d) * (2 * d);
ll bj = ld.second / (2 * d) * (2 * d);
ans[di] += intersect(rct, {{bi, bj}, {bi + d, bj + d}});
ans[di] -= intersect(rct, {{bi + d, bj}, {bi + 2 * d, bj + d}});
ans[di] -= intersect(rct, {{bi, bj + d}, {bi + d, bj + 2 * d}});
ans[di] += intersect(rct, {{bi + d, bj + d}, {bi + 2 * d, bj + 2 * d}});
}
}
ll mnans = n * n;
for (auto x : ans) {
mnans = min({mnans, x, n * n - x});
}
cout << mnans << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 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 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
64 ms |
1276 KB |
Output is correct |
2 |
Correct |
16 ms |
564 KB |
Output is correct |
3 |
Correct |
43 ms |
900 KB |
Output is correct |
4 |
Correct |
42 ms |
980 KB |
Output is correct |
5 |
Correct |
56 ms |
1136 KB |
Output is correct |
6 |
Correct |
37 ms |
724 KB |
Output is correct |
7 |
Correct |
8 ms |
340 KB |
Output is correct |
8 |
Correct |
37 ms |
852 KB |
Output is correct |
9 |
Correct |
107 ms |
1704 KB |
Output is correct |
10 |
Correct |
51 ms |
980 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
27 ms |
716 KB |
Output is correct |
17 |
Correct |
76 ms |
1620 KB |
Output is correct |
18 |
Correct |
93 ms |
1840 KB |
Output is correct |
19 |
Correct |
168 ms |
1676 KB |
Output is correct |
20 |
Correct |
189 ms |
1836 KB |
Output is correct |
21 |
Correct |
65 ms |
1492 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
54 ms |
960 KB |
Output is correct |
24 |
Correct |
79 ms |
1700 KB |
Output is correct |
25 |
Correct |
10 ms |
440 KB |
Output is correct |
26 |
Correct |
53 ms |
1176 KB |
Output is correct |
27 |
Correct |
72 ms |
1364 KB |
Output is correct |
28 |
Correct |
83 ms |
1748 KB |
Output is correct |
29 |
Correct |
30 ms |
724 KB |
Output is correct |
30 |
Correct |
3 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
64 ms |
1276 KB |
Output is correct |
2 |
Correct |
16 ms |
564 KB |
Output is correct |
3 |
Correct |
43 ms |
900 KB |
Output is correct |
4 |
Correct |
42 ms |
980 KB |
Output is correct |
5 |
Correct |
56 ms |
1136 KB |
Output is correct |
6 |
Correct |
37 ms |
724 KB |
Output is correct |
7 |
Correct |
8 ms |
340 KB |
Output is correct |
8 |
Correct |
37 ms |
852 KB |
Output is correct |
9 |
Correct |
107 ms |
1704 KB |
Output is correct |
10 |
Correct |
51 ms |
980 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
27 ms |
716 KB |
Output is correct |
27 |
Correct |
76 ms |
1620 KB |
Output is correct |
28 |
Correct |
93 ms |
1840 KB |
Output is correct |
29 |
Correct |
168 ms |
1676 KB |
Output is correct |
30 |
Correct |
189 ms |
1836 KB |
Output is correct |
31 |
Correct |
65 ms |
1492 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
54 ms |
960 KB |
Output is correct |
34 |
Correct |
79 ms |
1700 KB |
Output is correct |
35 |
Correct |
10 ms |
440 KB |
Output is correct |
36 |
Correct |
53 ms |
1176 KB |
Output is correct |
37 |
Correct |
72 ms |
1364 KB |
Output is correct |
38 |
Correct |
83 ms |
1748 KB |
Output is correct |
39 |
Correct |
30 ms |
724 KB |
Output is correct |
40 |
Correct |
3 ms |
340 KB |
Output is correct |
41 |
Correct |
156 ms |
1584 KB |
Output is correct |
42 |
Correct |
102 ms |
1760 KB |
Output is correct |
43 |
Correct |
126 ms |
1596 KB |
Output is correct |
44 |
Correct |
103 ms |
1716 KB |
Output is correct |
45 |
Correct |
101 ms |
1816 KB |
Output is correct |
46 |
Correct |
178 ms |
1748 KB |
Output is correct |
47 |
Correct |
91 ms |
1632 KB |
Output is correct |
48 |
Correct |
112 ms |
1624 KB |
Output is correct |
49 |
Correct |
94 ms |
1624 KB |
Output is correct |
50 |
Correct |
552 ms |
1716 KB |
Output is correct |
51 |
Correct |
604 ms |
1812 KB |
Output is correct |
52 |
Correct |
547 ms |
1704 KB |
Output is correct |
53 |
Correct |
587 ms |
1800 KB |
Output is correct |
54 |
Correct |
546 ms |
1740 KB |
Output is correct |
55 |
Correct |
615 ms |
1868 KB |
Output is correct |
56 |
Correct |
533 ms |
1620 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 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 |
Correct |
64 ms |
1276 KB |
Output is correct |
10 |
Correct |
16 ms |
564 KB |
Output is correct |
11 |
Correct |
43 ms |
900 KB |
Output is correct |
12 |
Correct |
42 ms |
980 KB |
Output is correct |
13 |
Correct |
56 ms |
1136 KB |
Output is correct |
14 |
Correct |
37 ms |
724 KB |
Output is correct |
15 |
Correct |
8 ms |
340 KB |
Output is correct |
16 |
Correct |
37 ms |
852 KB |
Output is correct |
17 |
Correct |
107 ms |
1704 KB |
Output is correct |
18 |
Correct |
51 ms |
980 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
1 ms |
212 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
27 ms |
716 KB |
Output is correct |
35 |
Correct |
76 ms |
1620 KB |
Output is correct |
36 |
Correct |
93 ms |
1840 KB |
Output is correct |
37 |
Correct |
168 ms |
1676 KB |
Output is correct |
38 |
Correct |
189 ms |
1836 KB |
Output is correct |
39 |
Correct |
65 ms |
1492 KB |
Output is correct |
40 |
Correct |
1 ms |
212 KB |
Output is correct |
41 |
Correct |
54 ms |
960 KB |
Output is correct |
42 |
Correct |
79 ms |
1700 KB |
Output is correct |
43 |
Correct |
10 ms |
440 KB |
Output is correct |
44 |
Correct |
53 ms |
1176 KB |
Output is correct |
45 |
Correct |
72 ms |
1364 KB |
Output is correct |
46 |
Correct |
83 ms |
1748 KB |
Output is correct |
47 |
Correct |
30 ms |
724 KB |
Output is correct |
48 |
Correct |
3 ms |
340 KB |
Output is correct |
49 |
Correct |
156 ms |
1584 KB |
Output is correct |
50 |
Correct |
102 ms |
1760 KB |
Output is correct |
51 |
Correct |
126 ms |
1596 KB |
Output is correct |
52 |
Correct |
103 ms |
1716 KB |
Output is correct |
53 |
Correct |
101 ms |
1816 KB |
Output is correct |
54 |
Correct |
178 ms |
1748 KB |
Output is correct |
55 |
Correct |
91 ms |
1632 KB |
Output is correct |
56 |
Correct |
112 ms |
1624 KB |
Output is correct |
57 |
Correct |
94 ms |
1624 KB |
Output is correct |
58 |
Correct |
552 ms |
1716 KB |
Output is correct |
59 |
Correct |
604 ms |
1812 KB |
Output is correct |
60 |
Correct |
547 ms |
1704 KB |
Output is correct |
61 |
Correct |
587 ms |
1800 KB |
Output is correct |
62 |
Correct |
546 ms |
1740 KB |
Output is correct |
63 |
Correct |
615 ms |
1868 KB |
Output is correct |
64 |
Correct |
533 ms |
1620 KB |
Output is correct |
65 |
Correct |
0 ms |
212 KB |
Output is correct |
66 |
Correct |
1 ms |
212 KB |
Output is correct |
67 |
Incorrect |
605 ms |
1872 KB |
Output isn't correct |
68 |
Halted |
0 ms |
0 KB |
- |