#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<n;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;
}
# |
Verdict |
Execution time |
Memory |
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 |
504 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
504 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
42 ms |
2384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
42 ms |
2384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
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 |
504 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
504 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Incorrect |
42 ms |
2384 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |