#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 5;
int n, k;
int xl[MAXN], xr[MAXN], yl[MAXN], yr[MAXN];
pair <int, int> Get(int p, int id)
{
if(p < 0)
{
return make_pair(0, 0);
}
int seg = p / id + 1;
int cw = (seg + 1) / 2, cb = seg / 2;
if(cw == cb)
{
return make_pair(cw * id, (cb - 1) * id + p % id + 1);
}
else
{
return make_pair((cw - 1) * id + p % id + 1, cb * id);
}
}
long long Solve(int id)
{
long long tmp = 1ll * (n / id) * (n / id) / 2;
long long curans = tmp * id * id;
for(int i = 1; i <= k; i++)
{
pair <int, int> AA = Get(xr[i], id), BB = Get(xl[i] - 1, id);
long long countxw = AA.first - BB.first, countxb = AA.second - BB.second;
AA = Get(yr[i], id), BB = Get(yl[i] - 1, id);
long long countyw = AA.first - BB.first, countyb = AA.second - BB.second;
long long corr = countyw * countxb + countyb * countxw, incorr = countyb * countxb + countyw * countxw;
curans -= corr;
curans += incorr;
}
return min(curans, 1ll * n * n - curans);
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> k;
for(int i = 1; i <= k; i++)
{
cin >> xl[i] >> yl[i] >> xr[i] >> yr[i];
xl[i]--;
yl[i]--;
xr[i]--;
yr[i]--;
}
long long ans = 1e18;
for(int i = 1; i < n; i++)
{
if(n % i == 0)
{
ans = min(ans, Solve(i));
}
}
cout << ans << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
1208 KB |
Output is correct |
2 |
Correct |
8 ms |
480 KB |
Output is correct |
3 |
Correct |
13 ms |
944 KB |
Output is correct |
4 |
Correct |
14 ms |
972 KB |
Output is correct |
5 |
Correct |
17 ms |
1108 KB |
Output is correct |
6 |
Correct |
13 ms |
872 KB |
Output is correct |
7 |
Correct |
3 ms |
332 KB |
Output is correct |
8 |
Correct |
13 ms |
844 KB |
Output is correct |
9 |
Correct |
29 ms |
1612 KB |
Output is correct |
10 |
Correct |
17 ms |
1008 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
284 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
0 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
284 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
0 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
10 ms |
716 KB |
Output is correct |
17 |
Correct |
24 ms |
1556 KB |
Output is correct |
18 |
Correct |
32 ms |
1788 KB |
Output is correct |
19 |
Correct |
95 ms |
1612 KB |
Output is correct |
20 |
Correct |
112 ms |
1848 KB |
Output is correct |
21 |
Correct |
21 ms |
1512 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
26 ms |
972 KB |
Output is correct |
24 |
Correct |
41 ms |
1696 KB |
Output is correct |
25 |
Correct |
5 ms |
460 KB |
Output is correct |
26 |
Correct |
25 ms |
1100 KB |
Output is correct |
27 |
Correct |
29 ms |
1380 KB |
Output is correct |
28 |
Correct |
33 ms |
1736 KB |
Output is correct |
29 |
Correct |
9 ms |
756 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
1208 KB |
Output is correct |
2 |
Correct |
8 ms |
480 KB |
Output is correct |
3 |
Correct |
13 ms |
944 KB |
Output is correct |
4 |
Correct |
14 ms |
972 KB |
Output is correct |
5 |
Correct |
17 ms |
1108 KB |
Output is correct |
6 |
Correct |
13 ms |
872 KB |
Output is correct |
7 |
Correct |
3 ms |
332 KB |
Output is correct |
8 |
Correct |
13 ms |
844 KB |
Output is correct |
9 |
Correct |
29 ms |
1612 KB |
Output is correct |
10 |
Correct |
17 ms |
1008 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
0 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
284 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
0 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
10 ms |
716 KB |
Output is correct |
27 |
Correct |
24 ms |
1556 KB |
Output is correct |
28 |
Correct |
32 ms |
1788 KB |
Output is correct |
29 |
Correct |
95 ms |
1612 KB |
Output is correct |
30 |
Correct |
112 ms |
1848 KB |
Output is correct |
31 |
Correct |
21 ms |
1512 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
26 ms |
972 KB |
Output is correct |
34 |
Correct |
41 ms |
1696 KB |
Output is correct |
35 |
Correct |
5 ms |
460 KB |
Output is correct |
36 |
Correct |
25 ms |
1100 KB |
Output is correct |
37 |
Correct |
29 ms |
1380 KB |
Output is correct |
38 |
Correct |
33 ms |
1736 KB |
Output is correct |
39 |
Correct |
9 ms |
756 KB |
Output is correct |
40 |
Correct |
1 ms |
332 KB |
Output is correct |
41 |
Correct |
91 ms |
1612 KB |
Output is correct |
42 |
Correct |
36 ms |
1784 KB |
Output is correct |
43 |
Correct |
55 ms |
1608 KB |
Output is correct |
44 |
Correct |
47 ms |
1612 KB |
Output is correct |
45 |
Correct |
34 ms |
1740 KB |
Output is correct |
46 |
Correct |
111 ms |
1752 KB |
Output is correct |
47 |
Correct |
28 ms |
1576 KB |
Output is correct |
48 |
Correct |
47 ms |
1668 KB |
Output is correct |
49 |
Correct |
33 ms |
1604 KB |
Output is correct |
50 |
Correct |
402 ms |
1844 KB |
Output is correct |
51 |
Correct |
460 ms |
4132 KB |
Output is correct |
52 |
Correct |
408 ms |
3896 KB |
Output is correct |
53 |
Correct |
458 ms |
4036 KB |
Output is correct |
54 |
Correct |
397 ms |
3904 KB |
Output is correct |
55 |
Correct |
439 ms |
4248 KB |
Output is correct |
56 |
Correct |
386 ms |
3712 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
29 ms |
1208 KB |
Output is correct |
10 |
Correct |
8 ms |
480 KB |
Output is correct |
11 |
Correct |
13 ms |
944 KB |
Output is correct |
12 |
Correct |
14 ms |
972 KB |
Output is correct |
13 |
Correct |
17 ms |
1108 KB |
Output is correct |
14 |
Correct |
13 ms |
872 KB |
Output is correct |
15 |
Correct |
3 ms |
332 KB |
Output is correct |
16 |
Correct |
13 ms |
844 KB |
Output is correct |
17 |
Correct |
29 ms |
1612 KB |
Output is correct |
18 |
Correct |
17 ms |
1008 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
0 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
0 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
284 KB |
Output is correct |
28 |
Correct |
1 ms |
204 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
0 ms |
332 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
1 ms |
332 KB |
Output is correct |
34 |
Correct |
10 ms |
716 KB |
Output is correct |
35 |
Correct |
24 ms |
1556 KB |
Output is correct |
36 |
Correct |
32 ms |
1788 KB |
Output is correct |
37 |
Correct |
95 ms |
1612 KB |
Output is correct |
38 |
Correct |
112 ms |
1848 KB |
Output is correct |
39 |
Correct |
21 ms |
1512 KB |
Output is correct |
40 |
Correct |
1 ms |
332 KB |
Output is correct |
41 |
Correct |
26 ms |
972 KB |
Output is correct |
42 |
Correct |
41 ms |
1696 KB |
Output is correct |
43 |
Correct |
5 ms |
460 KB |
Output is correct |
44 |
Correct |
25 ms |
1100 KB |
Output is correct |
45 |
Correct |
29 ms |
1380 KB |
Output is correct |
46 |
Correct |
33 ms |
1736 KB |
Output is correct |
47 |
Correct |
9 ms |
756 KB |
Output is correct |
48 |
Correct |
1 ms |
332 KB |
Output is correct |
49 |
Correct |
91 ms |
1612 KB |
Output is correct |
50 |
Correct |
36 ms |
1784 KB |
Output is correct |
51 |
Correct |
55 ms |
1608 KB |
Output is correct |
52 |
Correct |
47 ms |
1612 KB |
Output is correct |
53 |
Correct |
34 ms |
1740 KB |
Output is correct |
54 |
Correct |
111 ms |
1752 KB |
Output is correct |
55 |
Correct |
28 ms |
1576 KB |
Output is correct |
56 |
Correct |
47 ms |
1668 KB |
Output is correct |
57 |
Correct |
33 ms |
1604 KB |
Output is correct |
58 |
Correct |
402 ms |
1844 KB |
Output is correct |
59 |
Correct |
460 ms |
4132 KB |
Output is correct |
60 |
Correct |
408 ms |
3896 KB |
Output is correct |
61 |
Correct |
458 ms |
4036 KB |
Output is correct |
62 |
Correct |
397 ms |
3904 KB |
Output is correct |
63 |
Correct |
439 ms |
4248 KB |
Output is correct |
64 |
Correct |
386 ms |
3712 KB |
Output is correct |
65 |
Correct |
1 ms |
332 KB |
Output is correct |
66 |
Correct |
1 ms |
332 KB |
Output is correct |
67 |
Correct |
437 ms |
4012 KB |
Output is correct |
68 |
Correct |
432 ms |
3996 KB |
Output is correct |
69 |
Correct |
379 ms |
3540 KB |
Output is correct |
70 |
Correct |
402 ms |
3816 KB |
Output is correct |
71 |
Correct |
411 ms |
3832 KB |
Output is correct |
72 |
Correct |
394 ms |
3772 KB |
Output is correct |
73 |
Correct |
401 ms |
3664 KB |
Output is correct |
74 |
Correct |
448 ms |
3948 KB |
Output is correct |
75 |
Correct |
412 ms |
3896 KB |
Output is correct |
76 |
Correct |
444 ms |
4044 KB |
Output is correct |
77 |
Correct |
82 ms |
4224 KB |
Output is correct |
78 |
Correct |
39 ms |
3736 KB |
Output is correct |
79 |
Correct |
60 ms |
3660 KB |
Output is correct |
80 |
Correct |
83 ms |
3772 KB |
Output is correct |
81 |
Correct |
76 ms |
3552 KB |
Output is correct |
82 |
Correct |
51 ms |
4000 KB |
Output is correct |
83 |
Correct |
45 ms |
3652 KB |
Output is correct |
84 |
Correct |
272 ms |
4132 KB |
Output is correct |
85 |
Correct |
456 ms |
4164 KB |
Output is correct |
86 |
Correct |
1 ms |
332 KB |
Output is correct |
87 |
Correct |
1 ms |
332 KB |
Output is correct |
88 |
Correct |
472 ms |
4296 KB |
Output is correct |
89 |
Correct |
87 ms |
972 KB |
Output is correct |
90 |
Correct |
1 ms |
204 KB |
Output is correct |