#include <bits/stdc++.h>
using namespace std;
#define LL long long
const int lmax=1999999999;
const long long lmx=1999999999999999999;
const int N=200004;
int n, k, x1[N], y11[N], x2[N], y2[N];
LL ans;
int pos;
LL gety(LL y,LL she){
if(y <= 0) return 0;
LL res = (y / she) / 2 * she;
if((y / she) & 1) res += y % she + 1;
return res;
}
LL getx(LL x,LL she){
if(x <= 0) return 0;
LL res = (x / she) / 2 * she;
if((x / she) & 1) res += x % she + 1;
return res;
}
void solve(int she){
LL odd = 0, even = 0;
for(int i = 1,xx,yy; i <= k; i++){
LL o1 = gety(y2[i], she) - gety(y11[i] - 1, she);
LL e1 = (y2[i] - y11[i] + 1) - o1;
LL o2 = getx(x2[i], she) - getx(x1[i] - 1, she);
LL e2 = (x2[i] - x1[i] + 1) - o2;
xx = x1[i] / she;
yy = y11[i] / she;
if(xx & 1) swap(o1,e1);
if(yy & 1) swap(o2,e2);
LL od = 0, ev = 0;
if((xx + yy) & 1){
od = e1 * e2 + o1 * o2;
}
else{
od = o1 * e2 + e1 * o2;
}
ev = 1LL * (x2[i] - x1[i] + 1) * (y2[i] - y11[i] + 1) - od;
odd += od;
even += ev;
}
LL cnt = 1LL * (n / she) * (n / she);
LL res = min(cnt / 2 * she * she + even - odd, (cnt + 1) / 2 * she * she + odd - even);
if(res < ans){
pos = she;
ans = res;
}
}
int main(){std::ios::sync_with_stdio(false);
cin>>n>>k;
ans=1e18;
for(int i=1;i<=k;i++)
{
cin>>x1[i]>>y11[i]>>x2[i]>>y2[i];
x1[i]--;
y11[i]--;
x2[i]--;
y2[i]--;
}
for(int i=1;i*i<=n;i++)
{
if(n%i==0)
{
solve(i);
if(i>1&&i!=n/i)
{
solve(n/i);
}
}
}
cout<<ans<<endl;
}
/*
* *
* * * *
* * * *
* * * *
* * * *
* * *
* *
* *
* *
* *
* *
* *
* *
* *
*
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
452 KB |
Output is correct |
3 |
Correct |
2 ms |
452 KB |
Output is correct |
4 |
Correct |
3 ms |
472 KB |
Output is correct |
5 |
Correct |
2 ms |
652 KB |
Output is correct |
6 |
Correct |
2 ms |
652 KB |
Output is correct |
7 |
Correct |
2 ms |
652 KB |
Output is correct |
8 |
Correct |
3 ms |
652 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
33 ms |
1492 KB |
Output is correct |
2 |
Correct |
11 ms |
1492 KB |
Output is correct |
3 |
Correct |
25 ms |
2756 KB |
Output is correct |
4 |
Correct |
25 ms |
3472 KB |
Output is correct |
5 |
Correct |
31 ms |
4900 KB |
Output is correct |
6 |
Correct |
20 ms |
5372 KB |
Output is correct |
7 |
Correct |
6 ms |
5372 KB |
Output is correct |
8 |
Correct |
20 ms |
6444 KB |
Output is correct |
9 |
Correct |
55 ms |
9448 KB |
Output is correct |
10 |
Correct |
29 ms |
10064 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
10064 KB |
Output is correct |
2 |
Correct |
2 ms |
10064 KB |
Output is correct |
3 |
Correct |
2 ms |
10064 KB |
Output is correct |
4 |
Correct |
3 ms |
10064 KB |
Output is correct |
5 |
Correct |
3 ms |
10064 KB |
Output is correct |
6 |
Correct |
2 ms |
10064 KB |
Output is correct |
7 |
Correct |
3 ms |
10064 KB |
Output is correct |
8 |
Correct |
3 ms |
10064 KB |
Output is correct |
9 |
Correct |
2 ms |
10064 KB |
Output is correct |
10 |
Correct |
2 ms |
10064 KB |
Output is correct |
11 |
Correct |
2 ms |
10064 KB |
Output is correct |
12 |
Correct |
3 ms |
10064 KB |
Output is correct |
13 |
Correct |
4 ms |
10064 KB |
Output is correct |
14 |
Correct |
3 ms |
10064 KB |
Output is correct |
15 |
Correct |
3 ms |
10064 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
10064 KB |
Output is correct |
2 |
Correct |
2 ms |
10064 KB |
Output is correct |
3 |
Correct |
2 ms |
10064 KB |
Output is correct |
4 |
Correct |
3 ms |
10064 KB |
Output is correct |
5 |
Correct |
3 ms |
10064 KB |
Output is correct |
6 |
Correct |
2 ms |
10064 KB |
Output is correct |
7 |
Correct |
3 ms |
10064 KB |
Output is correct |
8 |
Correct |
3 ms |
10064 KB |
Output is correct |
9 |
Correct |
2 ms |
10064 KB |
Output is correct |
10 |
Correct |
2 ms |
10064 KB |
Output is correct |
11 |
Correct |
2 ms |
10064 KB |
Output is correct |
12 |
Correct |
3 ms |
10064 KB |
Output is correct |
13 |
Correct |
4 ms |
10064 KB |
Output is correct |
14 |
Correct |
3 ms |
10064 KB |
Output is correct |
15 |
Correct |
3 ms |
10064 KB |
Output is correct |
16 |
Correct |
18 ms |
10300 KB |
Output is correct |
17 |
Correct |
60 ms |
12536 KB |
Output is correct |
18 |
Correct |
67 ms |
14296 KB |
Output is correct |
19 |
Correct |
228 ms |
15628 KB |
Output is correct |
20 |
Correct |
258 ms |
17528 KB |
Output is correct |
21 |
Correct |
38 ms |
18412 KB |
Output is correct |
22 |
Correct |
4 ms |
18412 KB |
Output is correct |
23 |
Correct |
43 ms |
18656 KB |
Output is correct |
24 |
Correct |
59 ms |
20772 KB |
Output is correct |
25 |
Correct |
11 ms |
20772 KB |
Output is correct |
26 |
Correct |
37 ms |
21220 KB |
Output is correct |
27 |
Correct |
55 ms |
22568 KB |
Output is correct |
28 |
Correct |
63 ms |
24564 KB |
Output is correct |
29 |
Correct |
21 ms |
24564 KB |
Output is correct |
30 |
Correct |
4 ms |
24564 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
33 ms |
1492 KB |
Output is correct |
2 |
Correct |
11 ms |
1492 KB |
Output is correct |
3 |
Correct |
25 ms |
2756 KB |
Output is correct |
4 |
Correct |
25 ms |
3472 KB |
Output is correct |
5 |
Correct |
31 ms |
4900 KB |
Output is correct |
6 |
Correct |
20 ms |
5372 KB |
Output is correct |
7 |
Correct |
6 ms |
5372 KB |
Output is correct |
8 |
Correct |
20 ms |
6444 KB |
Output is correct |
9 |
Correct |
55 ms |
9448 KB |
Output is correct |
10 |
Correct |
29 ms |
10064 KB |
Output is correct |
11 |
Correct |
3 ms |
10064 KB |
Output is correct |
12 |
Correct |
2 ms |
10064 KB |
Output is correct |
13 |
Correct |
2 ms |
10064 KB |
Output is correct |
14 |
Correct |
3 ms |
10064 KB |
Output is correct |
15 |
Correct |
3 ms |
10064 KB |
Output is correct |
16 |
Correct |
2 ms |
10064 KB |
Output is correct |
17 |
Correct |
3 ms |
10064 KB |
Output is correct |
18 |
Correct |
3 ms |
10064 KB |
Output is correct |
19 |
Correct |
2 ms |
10064 KB |
Output is correct |
20 |
Correct |
2 ms |
10064 KB |
Output is correct |
21 |
Correct |
2 ms |
10064 KB |
Output is correct |
22 |
Correct |
3 ms |
10064 KB |
Output is correct |
23 |
Correct |
4 ms |
10064 KB |
Output is correct |
24 |
Correct |
3 ms |
10064 KB |
Output is correct |
25 |
Correct |
3 ms |
10064 KB |
Output is correct |
26 |
Correct |
18 ms |
10300 KB |
Output is correct |
27 |
Correct |
60 ms |
12536 KB |
Output is correct |
28 |
Correct |
67 ms |
14296 KB |
Output is correct |
29 |
Correct |
228 ms |
15628 KB |
Output is correct |
30 |
Correct |
258 ms |
17528 KB |
Output is correct |
31 |
Correct |
38 ms |
18412 KB |
Output is correct |
32 |
Correct |
4 ms |
18412 KB |
Output is correct |
33 |
Correct |
43 ms |
18656 KB |
Output is correct |
34 |
Correct |
59 ms |
20772 KB |
Output is correct |
35 |
Correct |
11 ms |
20772 KB |
Output is correct |
36 |
Correct |
37 ms |
21220 KB |
Output is correct |
37 |
Correct |
55 ms |
22568 KB |
Output is correct |
38 |
Correct |
63 ms |
24564 KB |
Output is correct |
39 |
Correct |
21 ms |
24564 KB |
Output is correct |
40 |
Correct |
4 ms |
24564 KB |
Output is correct |
41 |
Correct |
187 ms |
26940 KB |
Output is correct |
42 |
Correct |
65 ms |
29332 KB |
Output is correct |
43 |
Correct |
112 ms |
31208 KB |
Output is correct |
44 |
Correct |
68 ms |
33472 KB |
Output is correct |
45 |
Correct |
54 ms |
36040 KB |
Output is correct |
46 |
Correct |
215 ms |
38132 KB |
Output is correct |
47 |
Correct |
51 ms |
39988 KB |
Output is correct |
48 |
Correct |
90 ms |
42204 KB |
Output is correct |
49 |
Correct |
59 ms |
44144 KB |
Output is correct |
50 |
Correct |
986 ms |
46540 KB |
Output is correct |
51 |
Correct |
1071 ms |
48936 KB |
Output is correct |
52 |
Correct |
1046 ms |
50980 KB |
Output is correct |
53 |
Correct |
1106 ms |
53316 KB |
Output is correct |
54 |
Correct |
992 ms |
55372 KB |
Output is correct |
55 |
Correct |
1075 ms |
58008 KB |
Output is correct |
56 |
Correct |
925 ms |
59740 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
452 KB |
Output is correct |
3 |
Correct |
2 ms |
452 KB |
Output is correct |
4 |
Correct |
3 ms |
472 KB |
Output is correct |
5 |
Correct |
2 ms |
652 KB |
Output is correct |
6 |
Correct |
2 ms |
652 KB |
Output is correct |
7 |
Correct |
2 ms |
652 KB |
Output is correct |
8 |
Correct |
3 ms |
652 KB |
Output is correct |
9 |
Correct |
33 ms |
1492 KB |
Output is correct |
10 |
Correct |
11 ms |
1492 KB |
Output is correct |
11 |
Correct |
25 ms |
2756 KB |
Output is correct |
12 |
Correct |
25 ms |
3472 KB |
Output is correct |
13 |
Correct |
31 ms |
4900 KB |
Output is correct |
14 |
Correct |
20 ms |
5372 KB |
Output is correct |
15 |
Correct |
6 ms |
5372 KB |
Output is correct |
16 |
Correct |
20 ms |
6444 KB |
Output is correct |
17 |
Correct |
55 ms |
9448 KB |
Output is correct |
18 |
Correct |
29 ms |
10064 KB |
Output is correct |
19 |
Correct |
3 ms |
10064 KB |
Output is correct |
20 |
Correct |
2 ms |
10064 KB |
Output is correct |
21 |
Correct |
2 ms |
10064 KB |
Output is correct |
22 |
Correct |
3 ms |
10064 KB |
Output is correct |
23 |
Correct |
3 ms |
10064 KB |
Output is correct |
24 |
Correct |
2 ms |
10064 KB |
Output is correct |
25 |
Correct |
3 ms |
10064 KB |
Output is correct |
26 |
Correct |
3 ms |
10064 KB |
Output is correct |
27 |
Correct |
2 ms |
10064 KB |
Output is correct |
28 |
Correct |
2 ms |
10064 KB |
Output is correct |
29 |
Correct |
2 ms |
10064 KB |
Output is correct |
30 |
Correct |
3 ms |
10064 KB |
Output is correct |
31 |
Correct |
4 ms |
10064 KB |
Output is correct |
32 |
Correct |
3 ms |
10064 KB |
Output is correct |
33 |
Correct |
3 ms |
10064 KB |
Output is correct |
34 |
Correct |
18 ms |
10300 KB |
Output is correct |
35 |
Correct |
60 ms |
12536 KB |
Output is correct |
36 |
Correct |
67 ms |
14296 KB |
Output is correct |
37 |
Correct |
228 ms |
15628 KB |
Output is correct |
38 |
Correct |
258 ms |
17528 KB |
Output is correct |
39 |
Correct |
38 ms |
18412 KB |
Output is correct |
40 |
Correct |
4 ms |
18412 KB |
Output is correct |
41 |
Correct |
43 ms |
18656 KB |
Output is correct |
42 |
Correct |
59 ms |
20772 KB |
Output is correct |
43 |
Correct |
11 ms |
20772 KB |
Output is correct |
44 |
Correct |
37 ms |
21220 KB |
Output is correct |
45 |
Correct |
55 ms |
22568 KB |
Output is correct |
46 |
Correct |
63 ms |
24564 KB |
Output is correct |
47 |
Correct |
21 ms |
24564 KB |
Output is correct |
48 |
Correct |
4 ms |
24564 KB |
Output is correct |
49 |
Correct |
187 ms |
26940 KB |
Output is correct |
50 |
Correct |
65 ms |
29332 KB |
Output is correct |
51 |
Correct |
112 ms |
31208 KB |
Output is correct |
52 |
Correct |
68 ms |
33472 KB |
Output is correct |
53 |
Correct |
54 ms |
36040 KB |
Output is correct |
54 |
Correct |
215 ms |
38132 KB |
Output is correct |
55 |
Correct |
51 ms |
39988 KB |
Output is correct |
56 |
Correct |
90 ms |
42204 KB |
Output is correct |
57 |
Correct |
59 ms |
44144 KB |
Output is correct |
58 |
Correct |
986 ms |
46540 KB |
Output is correct |
59 |
Correct |
1071 ms |
48936 KB |
Output is correct |
60 |
Correct |
1046 ms |
50980 KB |
Output is correct |
61 |
Correct |
1106 ms |
53316 KB |
Output is correct |
62 |
Correct |
992 ms |
55372 KB |
Output is correct |
63 |
Correct |
1075 ms |
58008 KB |
Output is correct |
64 |
Correct |
925 ms |
59740 KB |
Output is correct |
65 |
Correct |
2 ms |
59740 KB |
Output is correct |
66 |
Correct |
2 ms |
59740 KB |
Output is correct |
67 |
Correct |
1029 ms |
62132 KB |
Output is correct |
68 |
Correct |
1068 ms |
64332 KB |
Output is correct |
69 |
Correct |
902 ms |
66168 KB |
Output is correct |
70 |
Correct |
1086 ms |
68416 KB |
Output is correct |
71 |
Correct |
959 ms |
70704 KB |
Output is correct |
72 |
Correct |
950 ms |
72740 KB |
Output is correct |
73 |
Correct |
926 ms |
74728 KB |
Output is correct |
74 |
Correct |
1142 ms |
76972 KB |
Output is correct |
75 |
Correct |
1026 ms |
79080 KB |
Output is correct |
76 |
Correct |
1002 ms |
81388 KB |
Output is correct |
77 |
Correct |
182 ms |
83736 KB |
Output is correct |
78 |
Correct |
78 ms |
85724 KB |
Output is correct |
79 |
Correct |
118 ms |
87720 KB |
Output is correct |
80 |
Correct |
134 ms |
89824 KB |
Output is correct |
81 |
Correct |
123 ms |
91720 KB |
Output is correct |
82 |
Correct |
106 ms |
94200 KB |
Output is correct |
83 |
Correct |
83 ms |
96284 KB |
Output is correct |
84 |
Correct |
740 ms |
98656 KB |
Output is correct |
85 |
Correct |
1147 ms |
100900 KB |
Output is correct |
86 |
Correct |
3 ms |
100900 KB |
Output is correct |
87 |
Correct |
2 ms |
100900 KB |
Output is correct |
88 |
Correct |
1109 ms |
103384 KB |
Output is correct |
89 |
Correct |
198 ms |
103384 KB |
Output is correct |
90 |
Correct |
2 ms |
103384 KB |
Output is correct |