#include<bits/stdc++.h>
using namespace std;
long long a,b,c,d,e,i,j,mas[1009][1009],jj,jjj,pas,zx,xc,zzx,zxc;
pair <pair <long long, long long>, pair <long long, long long> > p[100009];
int main(){
ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
cin>>a>>b;
pas=a*a;
for(i=1; i<=b; i++){
cin>>p[i].first.first>>p[i].first.second>>p[i].second.first>>p[i].second.second;
if(a<=1000){
mas[p[i].first.first][p[i].first.second]++;
}else{
if((p[i].first.first+p[i].first.second)%2==0) zx++; else xc++;
}
}
zzx=a/2*a/2;
zxc=(a/2+1)*(a/2+1);
if(a>1000){
d=xc+zxc-zx;
e=zx+zzx-xc;
cout<<min(d,e);
return 0;
}
for(i=1; i<=1002; i++){
for(j=1; j<=1002; j++) mas[i][j]+=mas[i-1][j]+mas[i][j-1]-mas[i-1][j-1];
}
for(c=1; c<a; c++){
if(a%c!=0) continue;
long long ans=0;
e=c*c;
for(i=c; i<=a; i+=c){
for(j=c; j<=a; j+=c){
d=mas[i][j]-mas[i-c][j]-mas[i][j-c]+mas[i-c][j-c];
if((i/c+j/c)%2==0) ans+=d; else ans+=e-d;
}
}
/* if(ans==11){
cout<<c<<" 1"<<endl;
}*/
if(pas>ans) pas=ans;
ans=0;
for(i=c; i<=a; i+=c){
for(j=c; j<=a; j+=c){
d=mas[i][j]-mas[i-c][j]-mas[i][j-c]+mas[i-c][j-c];
if((i/c+j/c)%2==1) ans+=d; else ans+=e-d;
}
}
/* if(ans==11){
cout<<c<<" 2"<<endl;
}*/
if(pas>ans) pas=ans;
}
cout<<pas;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
8312 KB |
Output is correct |
2 |
Correct |
12 ms |
8184 KB |
Output is correct |
3 |
Correct |
12 ms |
8312 KB |
Output is correct |
4 |
Correct |
12 ms |
8312 KB |
Output is correct |
5 |
Correct |
12 ms |
8184 KB |
Output is correct |
6 |
Correct |
12 ms |
8312 KB |
Output is correct |
7 |
Correct |
12 ms |
8312 KB |
Output is correct |
8 |
Correct |
12 ms |
8184 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
30 ms |
3192 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
8312 KB |
Output is correct |
2 |
Correct |
11 ms |
8312 KB |
Output is correct |
3 |
Correct |
12 ms |
8312 KB |
Output is correct |
4 |
Correct |
12 ms |
8320 KB |
Output is correct |
5 |
Correct |
12 ms |
8316 KB |
Output is correct |
6 |
Correct |
12 ms |
8312 KB |
Output is correct |
7 |
Correct |
12 ms |
8336 KB |
Output is correct |
8 |
Correct |
12 ms |
8356 KB |
Output is correct |
9 |
Correct |
12 ms |
8312 KB |
Output is correct |
10 |
Correct |
12 ms |
8184 KB |
Output is correct |
11 |
Correct |
12 ms |
8312 KB |
Output is correct |
12 |
Correct |
12 ms |
8312 KB |
Output is correct |
13 |
Correct |
12 ms |
8444 KB |
Output is correct |
14 |
Correct |
12 ms |
8288 KB |
Output is correct |
15 |
Correct |
12 ms |
8312 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
8312 KB |
Output is correct |
2 |
Correct |
11 ms |
8312 KB |
Output is correct |
3 |
Correct |
12 ms |
8312 KB |
Output is correct |
4 |
Correct |
12 ms |
8320 KB |
Output is correct |
5 |
Correct |
12 ms |
8316 KB |
Output is correct |
6 |
Correct |
12 ms |
8312 KB |
Output is correct |
7 |
Correct |
12 ms |
8336 KB |
Output is correct |
8 |
Correct |
12 ms |
8356 KB |
Output is correct |
9 |
Correct |
12 ms |
8312 KB |
Output is correct |
10 |
Correct |
12 ms |
8184 KB |
Output is correct |
11 |
Correct |
12 ms |
8312 KB |
Output is correct |
12 |
Correct |
12 ms |
8312 KB |
Output is correct |
13 |
Correct |
12 ms |
8444 KB |
Output is correct |
14 |
Correct |
12 ms |
8288 KB |
Output is correct |
15 |
Correct |
12 ms |
8312 KB |
Output is correct |
16 |
Correct |
51 ms |
9180 KB |
Output is correct |
17 |
Correct |
77 ms |
11000 KB |
Output is correct |
18 |
Correct |
83 ms |
11512 KB |
Output is correct |
19 |
Correct |
92 ms |
11168 KB |
Output is correct |
20 |
Correct |
93 ms |
11512 KB |
Output is correct |
21 |
Correct |
76 ms |
10872 KB |
Output is correct |
22 |
Correct |
50 ms |
8312 KB |
Output is correct |
23 |
Correct |
65 ms |
9720 KB |
Output is correct |
24 |
Correct |
81 ms |
11256 KB |
Output is correct |
25 |
Correct |
44 ms |
8824 KB |
Output is correct |
26 |
Correct |
63 ms |
10360 KB |
Output is correct |
27 |
Correct |
77 ms |
10656 KB |
Output is correct |
28 |
Correct |
88 ms |
11384 KB |
Output is correct |
29 |
Correct |
53 ms |
9592 KB |
Output is correct |
30 |
Correct |
46 ms |
8440 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
30 ms |
3192 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
8312 KB |
Output is correct |
2 |
Correct |
12 ms |
8184 KB |
Output is correct |
3 |
Correct |
12 ms |
8312 KB |
Output is correct |
4 |
Correct |
12 ms |
8312 KB |
Output is correct |
5 |
Correct |
12 ms |
8184 KB |
Output is correct |
6 |
Correct |
12 ms |
8312 KB |
Output is correct |
7 |
Correct |
12 ms |
8312 KB |
Output is correct |
8 |
Correct |
12 ms |
8184 KB |
Output is correct |
9 |
Incorrect |
30 ms |
3192 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |