Submission #168541

#TimeUsernameProblemLanguageResultExecution timeMemory
168541juggernautChessboard (IZhO18_chessboard)C++14
70 / 100
815 ms5880 KiB
//Just try and the idea will come! #include<bits/stdc++.h> #define int long long int #define fr first #define sc second using namespace std; int n,k,i,j,x,y,res; pair<int,int>p[100001],s[100001]; int get(int x1,int y1,int x2,int y2){ if(x1>x2||y1>y2)return 0; int res=(x2-x1+1)*((y2-y1+1)/2); if((y2-y1+1)&1){ res+=(x2-x1+1)/2; if((x1+y1)%2==0&&(x2-x1+1)%2==1)res++; } return res; } int get_x(int x1,int y1,int x2,int y2,int f){ if(x1>x2||y1>y2)return 0; int res,x,xx; x=(x1+f-1)/f; xx=(x2-f+1)/f; res=get(x,y1/f,xx,y1/f)*(y2-y1+1); if((x1+y1)%2==0)res+=max(0ll,(x*f-1-x1+1))*(y2-y1+1); if((x2+y2)%2==0)res+=max(0ll,(x2-xx*f))*(y2-y1+1); return res; } int get_y(int x1,int y1,int x2,int y2,int f){ if(x1>x2||y1>y2)return 0; int res,x,yy; y=(y1+f-1)/f; yy=(y2-f+1)/f; res=get(x/f,y,x/f,yy)*(x2-x1+1); if((x1+y1)%2==0)res+=max(0ll,(y*f-1-y1+1))*(x2-x1+1); if((x2+y2)%2==0)res+=max(0ll,(y2-yy*f))*(x2-x1+1); return res; } int count_white(int x1,int y1,int x2,int y2,int f){ int x,y,xx,yy,res; x=(x1+f-1)/f; y=(y1+f-1)/f; xx=(x2-f+1)/f; yy=(y2-f+1)/f; res=f*f*get(x,y,xx,yy); res+=get_x(x1,y1,x2,y-1,f)+get_x(x1,yy+1,x2,y2,f); res+=get_y(x1,y,x-1,yy,f)+get_y(xx+1,y,x2,yy,f); return res; } int get(int f){ int cnt=0,c[2],x; c[0]=c[1]=0; for(int i=0;i<k;i++){ x=get(s[i].fr/f,s[i].sc/f,p[i].fr/f,p[i].sc/f); c[0]+=x; c[1]+=(p[i].fr-s[i].fr+1)*(p[i].sc-s[i].sc+1)-x; } int m=n/f; int res=f*f*((m/2)*m+((m%2)*(m/2)))-c[1]+c[0]; res=min(res,f*f*((m/2)*m+((m%2)*((m+1)/2)))-c[0]+c[1]); return res; } main(){ scanf("%lld%lld",&n,&k); for(i=0;i<k;i++){ scanf("%lld%lld%lld%lld",&s[i].fr,&s[i].sc,&p[i].fr,&p[i].sc); p[i].fr--; p[i].sc--; s[i].fr--; s[i].sc--; } res=get(1); for(j=2;j*j<=n;j++){ if(n%j==0){ res=min(res,get(j)); res=min(res,get(n/j)); } } printf("%lld",res); }

Compilation message (stderr)

chessboard.cpp: In function 'long long int get(long long int)':
chessboard.cpp:50:9: warning: unused variable 'cnt' [-Wunused-variable]
     int cnt=0,c[2],x;
         ^~~
chessboard.cpp: At global scope:
chessboard.cpp:62:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
chessboard.cpp: In function 'int main()':
chessboard.cpp:63:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld%lld",&n,&k);
     ~~~~~^~~~~~~~~~~~~~~~~~
chessboard.cpp:65:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld%lld%lld%lld",&s[i].fr,&s[i].sc,&p[i].fr,&p[i].sc);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
chessboard.cpp: In function 'long long int get_y(long long int, long long int, long long int, long long int, long long int)':
chessboard.cpp:33:12: warning: 'x' may be used uninitialized in this function [-Wmaybe-uninitialized]
     res=get(x/f,y,x/f,yy)*(x2-x1+1);
         ~~~^~~~~~~~~~~~~~
#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...