#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include<bits/extc++.h>
//__gnu_pbds
struct square{
int x;int y;
int xp;int yp;
};
int main(){
ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int n,k;cin>>n>>k;
vector<ll> blackunion(n+1,0);
vector<square> s(k);
ll blacksum = 0;
for(int i=0;i<k;i++){
cin>>s[i].x>>s[i].xp>>s[i].y>>s[i].yp;
s[i].x--;
s[i].y--;
s[i].xp--;
s[i].yp--;
blacksum+=1LL*(s[i].y-s[i].x+1)*(s[i].yp-s[i].xp+1);
}
ll minn = LONG_LONG_MAX;
for(int d=1;d<n;d++){
if(n%d) continue;
for(int i=0;i<k;i++){
ll hoz = 0;
ll ver = 0;
int g = (s[i].y/d)-(s[i].x/d);
if(g==0) hoz = s[i].y-s[i].x+1;
else{
if(g&1){
hoz = (d*(g/2))+d-(s[i].x%d);
}else{
hoz = d-(s[i].x%d)+(s[i].y%d)+1+(d*((g-1)/2));
}
}
int h = (s[i].yp/d)-(s[i].xp/d);
if(h==0) ver = s[i].yp-s[i].xp+1;
else{
if(h&1){
ver = (d*(h/2))+d-(s[i].xp%d);
}else{
ver = d-(s[i].xp%d)+(s[i].yp%d)+1+(d*((h-1)/2));
}
}
//cout<<ver<<" "<<hoz<<"\n";
if((((s[i].x/d)&1)^((s[i].xp/d)&1))==0) blackunion[d]+=ver*hoz;
else blackunion[d]+=1LL*(s[i].y-s[i].x+1)*(s[i].yp-s[i].xp+1)-(ver*hoz);
}
ll allblack = 0;
if((n/d)&1) allblack= 1LL*d*d*(1LL*(n/d)*(((n/d)/2))+((n/d)/2+1));
else allblack = 1LL*d*d*(1LL*(n/d)*(n/d)/2);
//cout<<d<<" "<<blackunion[d]<<" "<<allblack<<" "<<blacksum<<"\n";
minn = min(minn,blacksum+allblack-2*blackunion[d]);
minn = min(minn,2*blackunion[d]+(1LL*n*n-allblack)-blacksum);
}
cout<<minn<<"\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
316 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
316 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
3192 KB |
Output is correct |
2 |
Correct |
5 ms |
980 KB |
Output is correct |
3 |
Correct |
12 ms |
2484 KB |
Output is correct |
4 |
Correct |
12 ms |
1864 KB |
Output is correct |
5 |
Correct |
15 ms |
2900 KB |
Output is correct |
6 |
Correct |
10 ms |
2004 KB |
Output is correct |
7 |
Correct |
3 ms |
724 KB |
Output is correct |
8 |
Correct |
10 ms |
1992 KB |
Output is correct |
9 |
Correct |
24 ms |
4016 KB |
Output is correct |
10 |
Correct |
14 ms |
2556 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
316 KB |
Output is correct |
3 |
Correct |
1 ms |
316 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 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 |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
324 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
316 KB |
Output is correct |
3 |
Correct |
1 ms |
316 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 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 |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
324 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
8 ms |
1108 KB |
Output is correct |
17 |
Correct |
20 ms |
2924 KB |
Output is correct |
18 |
Correct |
32 ms |
3416 KB |
Output is correct |
19 |
Correct |
76 ms |
3100 KB |
Output is correct |
20 |
Correct |
81 ms |
3412 KB |
Output is correct |
21 |
Correct |
19 ms |
2872 KB |
Output is correct |
22 |
Correct |
1 ms |
320 KB |
Output is correct |
23 |
Correct |
16 ms |
1620 KB |
Output is correct |
24 |
Correct |
24 ms |
3156 KB |
Output is correct |
25 |
Correct |
3 ms |
596 KB |
Output is correct |
26 |
Correct |
16 ms |
2124 KB |
Output is correct |
27 |
Correct |
29 ms |
2412 KB |
Output is correct |
28 |
Correct |
32 ms |
3392 KB |
Output is correct |
29 |
Correct |
8 ms |
1364 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
3192 KB |
Output is correct |
2 |
Correct |
5 ms |
980 KB |
Output is correct |
3 |
Correct |
12 ms |
2484 KB |
Output is correct |
4 |
Correct |
12 ms |
1864 KB |
Output is correct |
5 |
Correct |
15 ms |
2900 KB |
Output is correct |
6 |
Correct |
10 ms |
2004 KB |
Output is correct |
7 |
Correct |
3 ms |
724 KB |
Output is correct |
8 |
Correct |
10 ms |
1992 KB |
Output is correct |
9 |
Correct |
24 ms |
4016 KB |
Output is correct |
10 |
Correct |
14 ms |
2556 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
316 KB |
Output is correct |
13 |
Correct |
1 ms |
316 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 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 |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
324 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
8 ms |
1108 KB |
Output is correct |
27 |
Correct |
20 ms |
2924 KB |
Output is correct |
28 |
Correct |
32 ms |
3416 KB |
Output is correct |
29 |
Correct |
76 ms |
3100 KB |
Output is correct |
30 |
Correct |
81 ms |
3412 KB |
Output is correct |
31 |
Correct |
19 ms |
2872 KB |
Output is correct |
32 |
Correct |
1 ms |
320 KB |
Output is correct |
33 |
Correct |
16 ms |
1620 KB |
Output is correct |
34 |
Correct |
24 ms |
3156 KB |
Output is correct |
35 |
Correct |
3 ms |
596 KB |
Output is correct |
36 |
Correct |
16 ms |
2124 KB |
Output is correct |
37 |
Correct |
29 ms |
2412 KB |
Output is correct |
38 |
Correct |
32 ms |
3392 KB |
Output is correct |
39 |
Correct |
8 ms |
1364 KB |
Output is correct |
40 |
Correct |
1 ms |
340 KB |
Output is correct |
41 |
Correct |
70 ms |
4416 KB |
Output is correct |
42 |
Correct |
30 ms |
4736 KB |
Output is correct |
43 |
Correct |
44 ms |
4328 KB |
Output is correct |
44 |
Correct |
29 ms |
4708 KB |
Output is correct |
45 |
Correct |
27 ms |
4940 KB |
Output is correct |
46 |
Correct |
77 ms |
4772 KB |
Output is correct |
47 |
Correct |
24 ms |
4428 KB |
Output is correct |
48 |
Correct |
42 ms |
4428 KB |
Output is correct |
49 |
Correct |
27 ms |
4428 KB |
Output is correct |
50 |
Correct |
305 ms |
4556 KB |
Output is correct |
51 |
Correct |
327 ms |
4800 KB |
Output is correct |
52 |
Correct |
305 ms |
4424 KB |
Output is correct |
53 |
Correct |
324 ms |
4780 KB |
Output is correct |
54 |
Correct |
300 ms |
4488 KB |
Output is correct |
55 |
Correct |
335 ms |
4920 KB |
Output is correct |
56 |
Correct |
291 ms |
4380 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
316 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
316 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
18 ms |
3192 KB |
Output is correct |
10 |
Correct |
5 ms |
980 KB |
Output is correct |
11 |
Correct |
12 ms |
2484 KB |
Output is correct |
12 |
Correct |
12 ms |
1864 KB |
Output is correct |
13 |
Correct |
15 ms |
2900 KB |
Output is correct |
14 |
Correct |
10 ms |
2004 KB |
Output is correct |
15 |
Correct |
3 ms |
724 KB |
Output is correct |
16 |
Correct |
10 ms |
1992 KB |
Output is correct |
17 |
Correct |
24 ms |
4016 KB |
Output is correct |
18 |
Correct |
14 ms |
2556 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
316 KB |
Output is correct |
21 |
Correct |
1 ms |
316 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 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 |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
324 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
8 ms |
1108 KB |
Output is correct |
35 |
Correct |
20 ms |
2924 KB |
Output is correct |
36 |
Correct |
32 ms |
3416 KB |
Output is correct |
37 |
Correct |
76 ms |
3100 KB |
Output is correct |
38 |
Correct |
81 ms |
3412 KB |
Output is correct |
39 |
Correct |
19 ms |
2872 KB |
Output is correct |
40 |
Correct |
1 ms |
320 KB |
Output is correct |
41 |
Correct |
16 ms |
1620 KB |
Output is correct |
42 |
Correct |
24 ms |
3156 KB |
Output is correct |
43 |
Correct |
3 ms |
596 KB |
Output is correct |
44 |
Correct |
16 ms |
2124 KB |
Output is correct |
45 |
Correct |
29 ms |
2412 KB |
Output is correct |
46 |
Correct |
32 ms |
3392 KB |
Output is correct |
47 |
Correct |
8 ms |
1364 KB |
Output is correct |
48 |
Correct |
1 ms |
340 KB |
Output is correct |
49 |
Correct |
70 ms |
4416 KB |
Output is correct |
50 |
Correct |
30 ms |
4736 KB |
Output is correct |
51 |
Correct |
44 ms |
4328 KB |
Output is correct |
52 |
Correct |
29 ms |
4708 KB |
Output is correct |
53 |
Correct |
27 ms |
4940 KB |
Output is correct |
54 |
Correct |
77 ms |
4772 KB |
Output is correct |
55 |
Correct |
24 ms |
4428 KB |
Output is correct |
56 |
Correct |
42 ms |
4428 KB |
Output is correct |
57 |
Correct |
27 ms |
4428 KB |
Output is correct |
58 |
Correct |
305 ms |
4556 KB |
Output is correct |
59 |
Correct |
327 ms |
4800 KB |
Output is correct |
60 |
Correct |
305 ms |
4424 KB |
Output is correct |
61 |
Correct |
324 ms |
4780 KB |
Output is correct |
62 |
Correct |
300 ms |
4488 KB |
Output is correct |
63 |
Correct |
335 ms |
4920 KB |
Output is correct |
64 |
Correct |
291 ms |
4380 KB |
Output is correct |
65 |
Correct |
1 ms |
212 KB |
Output is correct |
66 |
Correct |
0 ms |
212 KB |
Output is correct |
67 |
Incorrect |
338 ms |
4672 KB |
Output isn't correct |
68 |
Halted |
0 ms |
0 KB |
- |