Submission #334374

#TimeUsernameProblemLanguageResultExecution timeMemory
334374juggernautChessboard (IZhO18_chessboard)C++14
70 / 100
484 ms3564 KiB
#include<bits/stdc++.h> using namespace std; #define int long long typedef long long ll; struct Rect{ int x,y,x2,y2; void _minus(){ x--,y--,x2--,y2--; } }rect[100005]; int n,m; ll solve(int side,bool color){ int sz=n/side; if(color){ ll wh=0,bl=side*side*((sz*sz+1)>>1); for(int i=0;i<m;i++){ int block_x=rect[i].x/side; int block_y=rect[i].y/side; if((block_x+block_y)&1)wh++; else bl--; } return wh+bl; }else{ ll wh=0,bl=side*side*((sz*sz)>>1); for(int i=0;i<m;i++){ bool cl; int block_x=rect[i].x/side; int block_y=rect[i].y/side; if((block_x+block_y)&1)bl--; else wh++; } return wh+bl; } } main(){ scanf("%lld%lld",&n,&m); for(int i=0;i<m;i++)scanf("%lld%lld%lld%lld",&rect[i].x,&rect[i].y,&rect[i].x2,&rect[i].y2),rect[i]._minus(); ll res=min(solve(1,0),solve(1,1)); for(int i=2;i*i<=n;i++)if(n%i==0)res=min(res,min(min(solve(i,0),solve(n/i,0)),min(solve(i,1),solve(n/i,1)))); printf("%lld",res); }

Compilation message (stderr)

chessboard.cpp: In function 'll solve(long long int, bool)':
chessboard.cpp:26:18: warning: unused variable 'cl' [-Wunused-variable]
   26 |             bool cl;
      |                  ^~
chessboard.cpp: At global scope:
chessboard.cpp:35:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   35 | main(){
      |      ^
chessboard.cpp: In function 'int main()':
chessboard.cpp:36:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   36 |     scanf("%lld%lld",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~~~~~
chessboard.cpp:37:30: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   37 |     for(int i=0;i<m;i++)scanf("%lld%lld%lld%lld",&rect[i].x,&rect[i].y,&rect[i].x2,&rect[i].y2),rect[i]._minus();
      |                         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...