#include <bits/stdc++.h>
using namespace std;
#define ll long long
vector <ll> p;
ll f(ll x1, ll y1, ll x2, ll y2){
ll z = (p[y2] - p[y1-1]);
z *= (p[x2] - p[x1-1]);
z += (((x2-x1+1) - (p[x2] - p[x1-1])) * ((y2-y1+1) - (p[y2] - p[y1-1])));
return z;
}
int main(){
ios::sync_with_stdio(false); cin.tie(nullptr);
ll n, k, k1 = 0;
cin >> n >> k;
vector <int> x1(k+1), y1(k+1), x2(k+1), y2(k+1);
for(int i = 1; i <= k; i++){
cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
ll a = (x2[i] - x1[i] + 1), b = (y2[i] - y1[i] + 1);
a *= b;
k1 += a;
}
ll ans = n, n1 = n;
ans *= n;
n1 *= n;
// cout << k1 << "\n";
for(ll x3 = 1; x3 < n; x3++){
if(n % x3 != 0) continue;
p.assign(n+2,0);
ll x = (x3 * 2), cnt = 0;
for(int i = 1; i <= n; i++){
p[i] = p[i-1] + ((i % x) <= (x / 2) and (i % x) != 0);
}
for(int i = 1; i <= k; i++){
cnt += f(x1[i], y1[i], x2[i], y2[i]);
}
// cout << x3 << ' ' << cnt << "\n";
ll y = ((x3 * x3) * (((n / x3) + 1) / 2) * (((n / x3) + 1) / 2)) + ((x3 * x3) * ((n / x3) / 2) * ((n / x3) / 2));
ans = min(ans, (y - cnt + (k1-cnt)));
ans = min(ans, (n1 - y) - (k1-cnt) + cnt);
}
cout << ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
2828 KB |
Output is correct |
2 |
Correct |
5 ms |
1104 KB |
Output is correct |
3 |
Correct |
11 ms |
2384 KB |
Output is correct |
4 |
Correct |
17 ms |
1772 KB |
Output is correct |
5 |
Correct |
14 ms |
1616 KB |
Output is correct |
6 |
Correct |
9 ms |
2128 KB |
Output is correct |
7 |
Correct |
3 ms |
848 KB |
Output is correct |
8 |
Correct |
9 ms |
2008 KB |
Output is correct |
9 |
Correct |
21 ms |
1872 KB |
Output is correct |
10 |
Correct |
13 ms |
1360 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
504 KB |
Output is correct |
16 |
Correct |
6 ms |
848 KB |
Output is correct |
17 |
Correct |
16 ms |
1616 KB |
Output is correct |
18 |
Correct |
23 ms |
2016 KB |
Output is correct |
19 |
Correct |
31 ms |
1852 KB |
Output is correct |
20 |
Correct |
28 ms |
2896 KB |
Output is correct |
21 |
Correct |
15 ms |
1616 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
9 ms |
1104 KB |
Output is correct |
24 |
Correct |
18 ms |
2836 KB |
Output is correct |
25 |
Correct |
2 ms |
592 KB |
Output is correct |
26 |
Correct |
11 ms |
1352 KB |
Output is correct |
27 |
Correct |
15 ms |
2128 KB |
Output is correct |
28 |
Correct |
19 ms |
2896 KB |
Output is correct |
29 |
Correct |
8 ms |
1528 KB |
Output is correct |
30 |
Correct |
2 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
2828 KB |
Output is correct |
2 |
Correct |
5 ms |
1104 KB |
Output is correct |
3 |
Correct |
11 ms |
2384 KB |
Output is correct |
4 |
Correct |
17 ms |
1772 KB |
Output is correct |
5 |
Correct |
14 ms |
1616 KB |
Output is correct |
6 |
Correct |
9 ms |
2128 KB |
Output is correct |
7 |
Correct |
3 ms |
848 KB |
Output is correct |
8 |
Correct |
9 ms |
2008 KB |
Output is correct |
9 |
Correct |
21 ms |
1872 KB |
Output is correct |
10 |
Correct |
13 ms |
1360 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
504 KB |
Output is correct |
26 |
Correct |
6 ms |
848 KB |
Output is correct |
27 |
Correct |
16 ms |
1616 KB |
Output is correct |
28 |
Correct |
23 ms |
2016 KB |
Output is correct |
29 |
Correct |
31 ms |
1852 KB |
Output is correct |
30 |
Correct |
28 ms |
2896 KB |
Output is correct |
31 |
Correct |
15 ms |
1616 KB |
Output is correct |
32 |
Correct |
1 ms |
336 KB |
Output is correct |
33 |
Correct |
9 ms |
1104 KB |
Output is correct |
34 |
Correct |
18 ms |
2836 KB |
Output is correct |
35 |
Correct |
2 ms |
592 KB |
Output is correct |
36 |
Correct |
11 ms |
1352 KB |
Output is correct |
37 |
Correct |
15 ms |
2128 KB |
Output is correct |
38 |
Correct |
19 ms |
2896 KB |
Output is correct |
39 |
Correct |
8 ms |
1528 KB |
Output is correct |
40 |
Correct |
2 ms |
336 KB |
Output is correct |
41 |
Correct |
34 ms |
2400 KB |
Output is correct |
42 |
Correct |
26 ms |
4936 KB |
Output is correct |
43 |
Correct |
27 ms |
4432 KB |
Output is correct |
44 |
Correct |
25 ms |
4688 KB |
Output is correct |
45 |
Correct |
24 ms |
4944 KB |
Output is correct |
46 |
Correct |
38 ms |
4688 KB |
Output is correct |
47 |
Correct |
21 ms |
4432 KB |
Output is correct |
48 |
Correct |
26 ms |
3408 KB |
Output is correct |
49 |
Correct |
23 ms |
4312 KB |
Output is correct |
50 |
Correct |
100 ms |
4432 KB |
Output is correct |
51 |
Correct |
102 ms |
4688 KB |
Output is correct |
52 |
Correct |
100 ms |
4444 KB |
Output is correct |
53 |
Correct |
98 ms |
4424 KB |
Output is correct |
54 |
Correct |
93 ms |
4520 KB |
Output is correct |
55 |
Correct |
106 ms |
4864 KB |
Output is correct |
56 |
Correct |
93 ms |
4176 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
16 ms |
2828 KB |
Output is correct |
10 |
Correct |
5 ms |
1104 KB |
Output is correct |
11 |
Correct |
11 ms |
2384 KB |
Output is correct |
12 |
Correct |
17 ms |
1772 KB |
Output is correct |
13 |
Correct |
14 ms |
1616 KB |
Output is correct |
14 |
Correct |
9 ms |
2128 KB |
Output is correct |
15 |
Correct |
3 ms |
848 KB |
Output is correct |
16 |
Correct |
9 ms |
2008 KB |
Output is correct |
17 |
Correct |
21 ms |
1872 KB |
Output is correct |
18 |
Correct |
13 ms |
1360 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
27 |
Correct |
1 ms |
336 KB |
Output is correct |
28 |
Correct |
1 ms |
336 KB |
Output is correct |
29 |
Correct |
1 ms |
336 KB |
Output is correct |
30 |
Correct |
1 ms |
336 KB |
Output is correct |
31 |
Correct |
1 ms |
336 KB |
Output is correct |
32 |
Correct |
1 ms |
336 KB |
Output is correct |
33 |
Correct |
1 ms |
504 KB |
Output is correct |
34 |
Correct |
6 ms |
848 KB |
Output is correct |
35 |
Correct |
16 ms |
1616 KB |
Output is correct |
36 |
Correct |
23 ms |
2016 KB |
Output is correct |
37 |
Correct |
31 ms |
1852 KB |
Output is correct |
38 |
Correct |
28 ms |
2896 KB |
Output is correct |
39 |
Correct |
15 ms |
1616 KB |
Output is correct |
40 |
Correct |
1 ms |
336 KB |
Output is correct |
41 |
Correct |
9 ms |
1104 KB |
Output is correct |
42 |
Correct |
18 ms |
2836 KB |
Output is correct |
43 |
Correct |
2 ms |
592 KB |
Output is correct |
44 |
Correct |
11 ms |
1352 KB |
Output is correct |
45 |
Correct |
15 ms |
2128 KB |
Output is correct |
46 |
Correct |
19 ms |
2896 KB |
Output is correct |
47 |
Correct |
8 ms |
1528 KB |
Output is correct |
48 |
Correct |
2 ms |
336 KB |
Output is correct |
49 |
Correct |
34 ms |
2400 KB |
Output is correct |
50 |
Correct |
26 ms |
4936 KB |
Output is correct |
51 |
Correct |
27 ms |
4432 KB |
Output is correct |
52 |
Correct |
25 ms |
4688 KB |
Output is correct |
53 |
Correct |
24 ms |
4944 KB |
Output is correct |
54 |
Correct |
38 ms |
4688 KB |
Output is correct |
55 |
Correct |
21 ms |
4432 KB |
Output is correct |
56 |
Correct |
26 ms |
3408 KB |
Output is correct |
57 |
Correct |
23 ms |
4312 KB |
Output is correct |
58 |
Correct |
100 ms |
4432 KB |
Output is correct |
59 |
Correct |
102 ms |
4688 KB |
Output is correct |
60 |
Correct |
100 ms |
4444 KB |
Output is correct |
61 |
Correct |
98 ms |
4424 KB |
Output is correct |
62 |
Correct |
93 ms |
4520 KB |
Output is correct |
63 |
Correct |
106 ms |
4864 KB |
Output is correct |
64 |
Correct |
93 ms |
4176 KB |
Output is correct |
65 |
Correct |
1 ms |
336 KB |
Output is correct |
66 |
Correct |
1 ms |
336 KB |
Output is correct |
67 |
Correct |
103 ms |
3588 KB |
Output is correct |
68 |
Correct |
101 ms |
4688 KB |
Output is correct |
69 |
Correct |
90 ms |
4176 KB |
Output is correct |
70 |
Correct |
84 ms |
4720 KB |
Output is correct |
71 |
Correct |
86 ms |
4444 KB |
Output is correct |
72 |
Correct |
90 ms |
4432 KB |
Output is correct |
73 |
Correct |
86 ms |
4432 KB |
Output is correct |
74 |
Correct |
91 ms |
4680 KB |
Output is correct |
75 |
Correct |
86 ms |
4432 KB |
Output is correct |
76 |
Correct |
98 ms |
4680 KB |
Output is correct |
77 |
Correct |
32 ms |
5112 KB |
Output is correct |
78 |
Correct |
22 ms |
4688 KB |
Output is correct |
79 |
Correct |
26 ms |
4432 KB |
Output is correct |
80 |
Correct |
27 ms |
4788 KB |
Output is correct |
81 |
Correct |
26 ms |
4432 KB |
Output is correct |
82 |
Correct |
26 ms |
4680 KB |
Output is correct |
83 |
Correct |
23 ms |
4432 KB |
Output is correct |
84 |
Correct |
66 ms |
4936 KB |
Output is correct |
85 |
Correct |
104 ms |
4944 KB |
Output is correct |
86 |
Correct |
30 ms |
1104 KB |
Output is correct |
87 |
Correct |
30 ms |
1104 KB |
Output is correct |
88 |
Correct |
98 ms |
4944 KB |
Output is correct |
89 |
Correct |
43 ms |
1632 KB |
Output is correct |
90 |
Correct |
30 ms |
1104 KB |
Output is correct |