Submission #378743

#TimeUsernameProblemLanguageResultExecution timeMemory
378743daniel920712Chessboard (IZhO18_chessboard)C++14
100 / 100
864 ms11172 KiB
#include <iostream> #include <stdio.h> #include <stdlib.h> #include <vector> #include <map> #include <set> #include <algorithm> using namespace std; vector < pair < long long , long long > > in[100005]; vector < pair < long long , long long > > out[100005]; vector < long long > have; int main() { long long N,M,ans=1e18,t,t2,a,b,c,d,i,j,k,x,y,m,n,l,r; scanf("%lld %lld",&N,&M); for(i=1;i<N;i++) if(N%i==0) have.push_back(i); while(M--) { scanf("%lld %lld %lld %lld",&a,&b,&c,&d); in[a].push_back(make_pair(b,d)); out[c+1].push_back(make_pair(b,d)); } for(auto i:have) { t=0; t2=0; a=0; b=0; c=0; d=0; a=N/i/2*i; c=N/i/2*i; if(N/i%2) c+=i; for(j=1;j<=N;j++) { for(auto k:out[j]) { l=(k.first-1)/i+1; r=(k.second-1)/i-1; if(r>=l) { x=y=(r-l+1)/2; if((r-l+1)%2) { if(l%2==0) x++; else y++; } d-=x*i; c+=x*i; b-=y*i; a+=y*i; } if((k.first-1)/i==(k.second-1)/i) { if((k.first-1)/i%2) { b-=(k.second-k.first+1); a+=(k.second-k.first+1); } else { d-=(k.second-k.first+1); c+=(k.second-k.first+1); } } else { if((k.first-1)/i%2) { b-=i-((k.first-1)%i); a+=i-((k.first-1)%i); } else { d-=i-((k.first-1)%i); c+=i-((k.first-1)%i); } if((k.second-1)/i%2) { b-=(k.second-1)%i+1; a+=(k.second-1)%i+1; } else { d-=(k.second-1)%i+1; c+=(k.second-1)%i+1; } } } for(auto k:in[j]) { l=(k.first-1)/i+1; r=(k.second-1)/i-1; if(r>=l) { x=y=(r-l+1)/2; if((r-l+1)%2) { if(l%2==0) x++; else y++; } d+=x*i; c-=x*i; b+=y*i; a-=y*i; } if((k.first-1)/i==(k.second-1)/i) { if((k.first-1)/i%2) { b+=(k.second-k.first+1); a-=(k.second-k.first+1); } else { d+=(k.second-k.first+1); c-=(k.second-k.first+1); } } else { if((k.first-1)/i%2) { b+=i-((k.first-1)%i); a-=i-((k.first-1)%i); } else { d+=i-((k.first-1)%i); c-=i-((k.first-1)%i); } if((k.second-1)/i%2) { b+=(k.second-1)%i+1; a-=(k.second-1)%i+1; } else { d+=(k.second-1)%i+1; c-=(k.second-1)%i+1; } } } if((j-1)/i%2) { t+=a; t+=d; t2+=b; t2+=c; } else { t2+=a; t2+=d; t+=b; t+=c; } //printf("%lld %lld %lld %lld %lld %lld\n",i,j,a,b,c,d); } ans=min(ans,t); ans=min(ans,t2); } printf("%lld\n",ans); return 0; } /* 6 8 3 3 3 3 1 2 1 2 3 4 3 4 5 5 5 5 4 3 4 3 4 4 4 4 2 1 2 1 3 6 3 6 */

Compilation message (stderr)

chessboard.cpp: In function 'int main()':
chessboard.cpp:15:45: warning: unused variable 'k' [-Wunused-variable]
   15 |     long long N,M,ans=1e18,t,t2,a,b,c,d,i,j,k,x,y,m,n,l,r;
      |                                             ^
chessboard.cpp:15:51: warning: unused variable 'm' [-Wunused-variable]
   15 |     long long N,M,ans=1e18,t,t2,a,b,c,d,i,j,k,x,y,m,n,l,r;
      |                                                   ^
chessboard.cpp:15:53: warning: unused variable 'n' [-Wunused-variable]
   15 |     long long N,M,ans=1e18,t,t2,a,b,c,d,i,j,k,x,y,m,n,l,r;
      |                                                     ^
chessboard.cpp:16:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   16 |     scanf("%lld %lld",&N,&M);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~
chessboard.cpp:20:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   20 |         scanf("%lld %lld %lld %lld",&a,&b,&c,&d);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...