Submission #1112648

#TimeUsernameProblemLanguageResultExecution timeMemory
1112648noyancanturkChessboard (IZhO18_chessboard)C++17
100 / 100
472 ms5384 KiB
#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; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...