# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
334372 | juggernaut | Chessboard (IZhO18_chessboard) | C++14 | 116 ms | 2028 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
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;
}
}
int main(){
scanf("%d%d",&n,&m);
for(int i=0;i<m;i++)scanf("%d%d%d%d",&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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |