#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include<bits/extc++.h>
//__gnu_pbds
#define int ll
struct square{
int x;int y;
int xp;int yp;
};
signed 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;
}
# |
Verdict |
Execution time |
Memory |
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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
2772 KB |
Output is correct |
2 |
Correct |
5 ms |
852 KB |
Output is correct |
3 |
Correct |
11 ms |
2132 KB |
Output is correct |
4 |
Correct |
11 ms |
1748 KB |
Output is correct |
5 |
Correct |
15 ms |
2480 KB |
Output is correct |
6 |
Correct |
10 ms |
1748 KB |
Output is correct |
7 |
Correct |
2 ms |
724 KB |
Output is correct |
8 |
Correct |
10 ms |
1748 KB |
Output is correct |
9 |
Correct |
30 ms |
3392 KB |
Output is correct |
10 |
Correct |
14 ms |
2132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
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 |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
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 |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
8 ms |
1108 KB |
Output is correct |
17 |
Correct |
19 ms |
2900 KB |
Output is correct |
18 |
Correct |
28 ms |
3412 KB |
Output is correct |
19 |
Correct |
72 ms |
3028 KB |
Output is correct |
20 |
Correct |
80 ms |
3412 KB |
Output is correct |
21 |
Correct |
24 ms |
2892 KB |
Output is correct |
22 |
Correct |
1 ms |
212 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 |
15 ms |
2004 KB |
Output is correct |
27 |
Correct |
22 ms |
2388 KB |
Output is correct |
28 |
Correct |
32 ms |
3284 KB |
Output is correct |
29 |
Correct |
8 ms |
1364 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
2772 KB |
Output is correct |
2 |
Correct |
5 ms |
852 KB |
Output is correct |
3 |
Correct |
11 ms |
2132 KB |
Output is correct |
4 |
Correct |
11 ms |
1748 KB |
Output is correct |
5 |
Correct |
15 ms |
2480 KB |
Output is correct |
6 |
Correct |
10 ms |
1748 KB |
Output is correct |
7 |
Correct |
2 ms |
724 KB |
Output is correct |
8 |
Correct |
10 ms |
1748 KB |
Output is correct |
9 |
Correct |
30 ms |
3392 KB |
Output is correct |
10 |
Correct |
14 ms |
2132 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 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 |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
8 ms |
1108 KB |
Output is correct |
27 |
Correct |
19 ms |
2900 KB |
Output is correct |
28 |
Correct |
28 ms |
3412 KB |
Output is correct |
29 |
Correct |
72 ms |
3028 KB |
Output is correct |
30 |
Correct |
80 ms |
3412 KB |
Output is correct |
31 |
Correct |
24 ms |
2892 KB |
Output is correct |
32 |
Correct |
1 ms |
212 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 |
15 ms |
2004 KB |
Output is correct |
37 |
Correct |
22 ms |
2388 KB |
Output is correct |
38 |
Correct |
32 ms |
3284 KB |
Output is correct |
39 |
Correct |
8 ms |
1364 KB |
Output is correct |
40 |
Correct |
1 ms |
340 KB |
Output is correct |
41 |
Correct |
76 ms |
3680 KB |
Output is correct |
42 |
Correct |
34 ms |
4052 KB |
Output is correct |
43 |
Correct |
47 ms |
3696 KB |
Output is correct |
44 |
Correct |
29 ms |
3924 KB |
Output is correct |
45 |
Correct |
27 ms |
4156 KB |
Output is correct |
46 |
Correct |
78 ms |
3996 KB |
Output is correct |
47 |
Correct |
24 ms |
3668 KB |
Output is correct |
48 |
Correct |
40 ms |
3816 KB |
Output is correct |
49 |
Correct |
31 ms |
3668 KB |
Output is correct |
50 |
Correct |
307 ms |
3840 KB |
Output is correct |
51 |
Correct |
324 ms |
3992 KB |
Output is correct |
52 |
Correct |
301 ms |
3796 KB |
Output is correct |
53 |
Correct |
324 ms |
3976 KB |
Output is correct |
54 |
Correct |
302 ms |
3744 KB |
Output is correct |
55 |
Correct |
334 ms |
4100 KB |
Output is correct |
56 |
Correct |
302 ms |
3668 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
17 ms |
2772 KB |
Output is correct |
10 |
Correct |
5 ms |
852 KB |
Output is correct |
11 |
Correct |
11 ms |
2132 KB |
Output is correct |
12 |
Correct |
11 ms |
1748 KB |
Output is correct |
13 |
Correct |
15 ms |
2480 KB |
Output is correct |
14 |
Correct |
10 ms |
1748 KB |
Output is correct |
15 |
Correct |
2 ms |
724 KB |
Output is correct |
16 |
Correct |
10 ms |
1748 KB |
Output is correct |
17 |
Correct |
30 ms |
3392 KB |
Output is correct |
18 |
Correct |
14 ms |
2132 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 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 |
0 ms |
212 KB |
Output is correct |
29 |
Correct |
0 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
8 ms |
1108 KB |
Output is correct |
35 |
Correct |
19 ms |
2900 KB |
Output is correct |
36 |
Correct |
28 ms |
3412 KB |
Output is correct |
37 |
Correct |
72 ms |
3028 KB |
Output is correct |
38 |
Correct |
80 ms |
3412 KB |
Output is correct |
39 |
Correct |
24 ms |
2892 KB |
Output is correct |
40 |
Correct |
1 ms |
212 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 |
15 ms |
2004 KB |
Output is correct |
45 |
Correct |
22 ms |
2388 KB |
Output is correct |
46 |
Correct |
32 ms |
3284 KB |
Output is correct |
47 |
Correct |
8 ms |
1364 KB |
Output is correct |
48 |
Correct |
1 ms |
340 KB |
Output is correct |
49 |
Correct |
76 ms |
3680 KB |
Output is correct |
50 |
Correct |
34 ms |
4052 KB |
Output is correct |
51 |
Correct |
47 ms |
3696 KB |
Output is correct |
52 |
Correct |
29 ms |
3924 KB |
Output is correct |
53 |
Correct |
27 ms |
4156 KB |
Output is correct |
54 |
Correct |
78 ms |
3996 KB |
Output is correct |
55 |
Correct |
24 ms |
3668 KB |
Output is correct |
56 |
Correct |
40 ms |
3816 KB |
Output is correct |
57 |
Correct |
31 ms |
3668 KB |
Output is correct |
58 |
Correct |
307 ms |
3840 KB |
Output is correct |
59 |
Correct |
324 ms |
3992 KB |
Output is correct |
60 |
Correct |
301 ms |
3796 KB |
Output is correct |
61 |
Correct |
324 ms |
3976 KB |
Output is correct |
62 |
Correct |
302 ms |
3744 KB |
Output is correct |
63 |
Correct |
334 ms |
4100 KB |
Output is correct |
64 |
Correct |
302 ms |
3668 KB |
Output is correct |
65 |
Correct |
0 ms |
212 KB |
Output is correct |
66 |
Correct |
0 ms |
212 KB |
Output is correct |
67 |
Incorrect |
342 ms |
3900 KB |
Output isn't correct |
68 |
Halted |
0 ms |
0 KB |
- |