#include<bits/stdc++.h>
using namespace std;
#define int long long
using pii=pair<int,int>;
signed main(){
int n,k;
cin>>n>>k;
int a[k],b[k],c[k],d[k];
for(int i=0;i<k;i++){
cin>>a[i]>>b[i]>>c[i]>>d[i];
}
int ans=n*n;
for(int len=1;len<n;len++){
if(n%len)continue;
auto cntfind=[&](int x,int y)->pii {
if(!x||!y)return pii{0,0};
int st1,nd1;
if((x/len)%2==1){
st1=(x/len/2+1)*len;
nd1=x-st1;
}else{
nd1=(x/len/2)*len;
st1=x-nd1;
}
int st2,nd2;
if((y/len)%2==1){
st2=(y/len/2+1)*len;
nd2=y-st2;
}else{
nd2=(y/len/2)*len;
st2=y-nd2;
}
return pii{st1*st2+nd1*nd2,x*y-(st1*st2+nd1*nd2)};
};
pii res=cntfind(n,n);
int need1=res.first,need2=res.second;
for(int i=0;i<k;i++){
int xx=a[i],yx=b[i],xy=c[i],yy=d[i];
res=cntfind(xy,yy);
need1-=res.first-res.second;
need2-=res.second-res.first;
res=cntfind(xx-1,yx-1);
need1-=res.first-res.second;
need2-=res.second-res.first;
res=cntfind(xx-1,yy);
need1-=res.second-res.first;
need2-=res.first-res.second;
res=cntfind(xy,yx-1);
need1-=res.second-res.first;
need2-=res.first-res.second;
}
ans=min({ans,need1,need2});
}
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 |
41 ms |
2384 KB |
Output is correct |
2 |
Correct |
11 ms |
848 KB |
Output is correct |
3 |
Correct |
27 ms |
1616 KB |
Output is correct |
4 |
Correct |
27 ms |
1616 KB |
Output is correct |
5 |
Correct |
41 ms |
3160 KB |
Output is correct |
6 |
Correct |
24 ms |
2128 KB |
Output is correct |
7 |
Correct |
5 ms |
592 KB |
Output is correct |
8 |
Correct |
27 ms |
2128 KB |
Output is correct |
9 |
Correct |
60 ms |
3240 KB |
Output is correct |
10 |
Correct |
35 ms |
2040 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 |
2 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 |
2 ms |
336 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 |
2 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 |
2 ms |
336 KB |
Output is correct |
16 |
Correct |
21 ms |
1288 KB |
Output is correct |
17 |
Correct |
47 ms |
3664 KB |
Output is correct |
18 |
Correct |
71 ms |
3408 KB |
Output is correct |
19 |
Correct |
123 ms |
3408 KB |
Output is correct |
20 |
Correct |
134 ms |
4184 KB |
Output is correct |
21 |
Correct |
44 ms |
3896 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
39 ms |
1500 KB |
Output is correct |
24 |
Correct |
55 ms |
3656 KB |
Output is correct |
25 |
Correct |
8 ms |
592 KB |
Output is correct |
26 |
Correct |
34 ms |
2128 KB |
Output is correct |
27 |
Correct |
46 ms |
2888 KB |
Output is correct |
28 |
Correct |
60 ms |
3656 KB |
Output is correct |
29 |
Correct |
19 ms |
1872 KB |
Output is correct |
30 |
Correct |
3 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
41 ms |
2384 KB |
Output is correct |
2 |
Correct |
11 ms |
848 KB |
Output is correct |
3 |
Correct |
27 ms |
1616 KB |
Output is correct |
4 |
Correct |
27 ms |
1616 KB |
Output is correct |
5 |
Correct |
41 ms |
3160 KB |
Output is correct |
6 |
Correct |
24 ms |
2128 KB |
Output is correct |
7 |
Correct |
5 ms |
592 KB |
Output is correct |
8 |
Correct |
27 ms |
2128 KB |
Output is correct |
9 |
Correct |
60 ms |
3240 KB |
Output is correct |
10 |
Correct |
35 ms |
2040 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 |
2 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 |
2 ms |
336 KB |
Output is correct |
26 |
Correct |
21 ms |
1288 KB |
Output is correct |
27 |
Correct |
47 ms |
3664 KB |
Output is correct |
28 |
Correct |
71 ms |
3408 KB |
Output is correct |
29 |
Correct |
123 ms |
3408 KB |
Output is correct |
30 |
Correct |
134 ms |
4184 KB |
Output is correct |
31 |
Correct |
44 ms |
3896 KB |
Output is correct |
32 |
Correct |
1 ms |
336 KB |
Output is correct |
33 |
Correct |
39 ms |
1500 KB |
Output is correct |
34 |
Correct |
55 ms |
3656 KB |
Output is correct |
35 |
Correct |
8 ms |
592 KB |
Output is correct |
36 |
Correct |
34 ms |
2128 KB |
Output is correct |
37 |
Correct |
46 ms |
2888 KB |
Output is correct |
38 |
Correct |
60 ms |
3656 KB |
Output is correct |
39 |
Correct |
19 ms |
1872 KB |
Output is correct |
40 |
Correct |
3 ms |
336 KB |
Output is correct |
41 |
Correct |
112 ms |
2896 KB |
Output is correct |
42 |
Correct |
75 ms |
4616 KB |
Output is correct |
43 |
Correct |
90 ms |
3832 KB |
Output is correct |
44 |
Correct |
71 ms |
3320 KB |
Output is correct |
45 |
Correct |
67 ms |
3912 KB |
Output is correct |
46 |
Correct |
139 ms |
3912 KB |
Output is correct |
47 |
Correct |
64 ms |
2896 KB |
Output is correct |
48 |
Correct |
75 ms |
4168 KB |
Output is correct |
49 |
Correct |
65 ms |
3800 KB |
Output is correct |
50 |
Correct |
400 ms |
3912 KB |
Output is correct |
51 |
Correct |
428 ms |
4680 KB |
Output is correct |
52 |
Correct |
405 ms |
5192 KB |
Output is correct |
53 |
Correct |
417 ms |
4492 KB |
Output is correct |
54 |
Correct |
400 ms |
4732 KB |
Output is correct |
55 |
Correct |
442 ms |
4896 KB |
Output is correct |
56 |
Correct |
386 ms |
4936 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 |
41 ms |
2384 KB |
Output is correct |
10 |
Correct |
11 ms |
848 KB |
Output is correct |
11 |
Correct |
27 ms |
1616 KB |
Output is correct |
12 |
Correct |
27 ms |
1616 KB |
Output is correct |
13 |
Correct |
41 ms |
3160 KB |
Output is correct |
14 |
Correct |
24 ms |
2128 KB |
Output is correct |
15 |
Correct |
5 ms |
592 KB |
Output is correct |
16 |
Correct |
27 ms |
2128 KB |
Output is correct |
17 |
Correct |
60 ms |
3240 KB |
Output is correct |
18 |
Correct |
35 ms |
2040 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 |
2 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 |
2 ms |
336 KB |
Output is correct |
34 |
Correct |
21 ms |
1288 KB |
Output is correct |
35 |
Correct |
47 ms |
3664 KB |
Output is correct |
36 |
Correct |
71 ms |
3408 KB |
Output is correct |
37 |
Correct |
123 ms |
3408 KB |
Output is correct |
38 |
Correct |
134 ms |
4184 KB |
Output is correct |
39 |
Correct |
44 ms |
3896 KB |
Output is correct |
40 |
Correct |
1 ms |
336 KB |
Output is correct |
41 |
Correct |
39 ms |
1500 KB |
Output is correct |
42 |
Correct |
55 ms |
3656 KB |
Output is correct |
43 |
Correct |
8 ms |
592 KB |
Output is correct |
44 |
Correct |
34 ms |
2128 KB |
Output is correct |
45 |
Correct |
46 ms |
2888 KB |
Output is correct |
46 |
Correct |
60 ms |
3656 KB |
Output is correct |
47 |
Correct |
19 ms |
1872 KB |
Output is correct |
48 |
Correct |
3 ms |
336 KB |
Output is correct |
49 |
Correct |
112 ms |
2896 KB |
Output is correct |
50 |
Correct |
75 ms |
4616 KB |
Output is correct |
51 |
Correct |
90 ms |
3832 KB |
Output is correct |
52 |
Correct |
71 ms |
3320 KB |
Output is correct |
53 |
Correct |
67 ms |
3912 KB |
Output is correct |
54 |
Correct |
139 ms |
3912 KB |
Output is correct |
55 |
Correct |
64 ms |
2896 KB |
Output is correct |
56 |
Correct |
75 ms |
4168 KB |
Output is correct |
57 |
Correct |
65 ms |
3800 KB |
Output is correct |
58 |
Correct |
400 ms |
3912 KB |
Output is correct |
59 |
Correct |
428 ms |
4680 KB |
Output is correct |
60 |
Correct |
405 ms |
5192 KB |
Output is correct |
61 |
Correct |
417 ms |
4492 KB |
Output is correct |
62 |
Correct |
400 ms |
4732 KB |
Output is correct |
63 |
Correct |
442 ms |
4896 KB |
Output is correct |
64 |
Correct |
386 ms |
4936 KB |
Output is correct |
65 |
Correct |
1 ms |
336 KB |
Output is correct |
66 |
Correct |
1 ms |
336 KB |
Output is correct |
67 |
Correct |
427 ms |
5240 KB |
Output is correct |
68 |
Correct |
419 ms |
5384 KB |
Output is correct |
69 |
Correct |
371 ms |
3108 KB |
Output is correct |
70 |
Correct |
389 ms |
4424 KB |
Output is correct |
71 |
Correct |
392 ms |
5036 KB |
Output is correct |
72 |
Correct |
380 ms |
4168 KB |
Output is correct |
73 |
Correct |
380 ms |
3836 KB |
Output is correct |
74 |
Correct |
421 ms |
4596 KB |
Output is correct |
75 |
Correct |
420 ms |
4688 KB |
Output is correct |
76 |
Correct |
444 ms |
4784 KB |
Output is correct |
77 |
Correct |
114 ms |
4680 KB |
Output is correct |
78 |
Correct |
67 ms |
4448 KB |
Output is correct |
79 |
Correct |
89 ms |
3068 KB |
Output is correct |
80 |
Correct |
110 ms |
3876 KB |
Output is correct |
81 |
Correct |
85 ms |
4004 KB |
Output is correct |
82 |
Correct |
96 ms |
4652 KB |
Output is correct |
83 |
Correct |
93 ms |
2896 KB |
Output is correct |
84 |
Correct |
285 ms |
4944 KB |
Output is correct |
85 |
Correct |
472 ms |
4936 KB |
Output is correct |
86 |
Correct |
1 ms |
336 KB |
Output is correct |
87 |
Correct |
1 ms |
336 KB |
Output is correct |
88 |
Correct |
467 ms |
5060 KB |
Output is correct |
89 |
Correct |
93 ms |
996 KB |
Output is correct |
90 |
Correct |
1 ms |
336 KB |
Output is correct |