Submission #138004

#TimeUsernameProblemLanguageResultExecution timeMemory
138004vardan__02Chessboard (IZhO18_chessboard)C++14
100 / 100
911 ms5884 KiB
#include <iostream> #include <fstream> #include <algorithm> #include <cstring> #include <string> #include <vector> #include <cstdio> #include <queue> #include <deque> #include <stack> #include <cmath> #include <list> #include <set> #include <map> using namespace std; typedef long long ll; #define MP make_pair #define PB push_back ll n,k,p,u,ans,i,j,v,x1[100005],x2[100005],y[100005],y2[100005],ans1,ans2,t,q; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin>>n>>k; for(i=1;i<=k;i++) { cin>>x1[i]>>y[i]>>x2[i]>>y2[i]; ll kent1=0,kent2=0,zuyg1=0,zuyg2=0,t1,t2; t1=x2[i]-x1[i]+1; if(x1[i]%2==0) { zuyg1+=(t1+1)/2; kent1+=t1/2; } else { kent1+=(t1+1)/2; zuyg1+=t1/2; } t2=y2[i]-y[i]+1; if(y[i]%2==0) { zuyg2+=(t2+1)/2; kent2+=t2/2; } else { kent2+=(t2+1)/2; zuyg2+=t2/2; } u+=kent1*kent2+zuyg1*zuyg2; v+=kent1*zuyg2+zuyg1*kent2; } if(n%2==0) p=n*n/2; else p=n*n/2+1; q=n*n/2; ans=min(p-u+v,q-v+u); for(j=2;j<=n;j++) { if(n%j==0) { u=0; v=0; t=n/j; for(i=1;i<=k;i++) { ll kent1=0,kent2=0,zuyg1=0,zuyg2=0,t1,t2,arajin1=0,arajin2=0,verjin1=0,verjin2=0,g; arajin1=(x1[i]-1)/t+1; if(x2[i]%t==0) verjin1=x2[i]/t; else verjin1=x2[i]/t+1; arajin2=(y[i]-1)/t+1; if(y2[i]%t==0) verjin2=y2[i]/t; else verjin2=y2[i]/t+1; if(arajin1==verjin1) { if(arajin1%2==0) zuyg1+=x2[i]-x1[i]+1; else kent1=x2[i]-x1[i]+1; } else { if((x1[i]-1)%t==0) { if(arajin1%2==0) zuyg1+=t; else kent1+=t; } else { t1=t-(x1[i]-1)%t; if(arajin1%2==0) zuyg1+=t1; else kent1+=t1; } arajin1++; if(x2[i]%t==0) { if(verjin1%2==0) zuyg1+=t; else kent1+=t; } else { t1=x2[i]%t; if(verjin1%2==0) zuyg1+=t1; else kent1+=t1; } verjin1--; g=verjin1-arajin1+1; if(arajin1%2==0) { t1=(g+1)/2; t2=g/2; } else { t1=g/2; t2=(g+1)/2; } zuyg1+=t1*t; kent1+=t2*t; } if(arajin2==verjin2) { if(arajin2%2==0) zuyg2+=y2[i]-y[i]+1; else kent2=y2[i]-y[i]+1; } else { if((y[i]-1)%t==0) { if(arajin2%2==0) zuyg2+=t; else kent2+=t; } else { t1=t-(y[i]-1)%t; if(arajin2%2==0) zuyg2+=t1; else kent2+=t1; } arajin2++; if(y2[i]%t==0) { if(verjin2%2==0) zuyg2+=t; else kent2+=t; } else { t1=y2[i]%t; if(verjin2%2==0) zuyg2+=t1; else kent2+=t1; } verjin2--; g=verjin2-arajin2+1; if(arajin2%2==0) { t1=(g+1)/2; t2=g/2; } else { t1=g/2; t2=(g+1)/2; } zuyg2+=t1*t; kent2+=t2*t; } u+=kent1*kent2+zuyg1*zuyg2; v+=kent1*zuyg2+zuyg1*kent2; } q=n/j; if(j%2==1) ans1=j*j/2+1; else ans1=j*j/2; ans1=ans1*q*q; ans1=ans1-u+v; ans2=j*j/2; ans2=ans2*q*q; ans2=ans2-v+u; ans=min(ans,ans2); ans=min(ans,ans1); } } cout<<ans<<endl; return 0; }
#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...