# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
334381 | juggernaut | Chessboard (IZhO18_chessboard) | C++14 | 253 ms | 3564 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{
ll x,y,x2,y2;
void _minus(){
x--,y--,x2--,y2--;
}
}rect[100005];
ll n,m;
ll solve(ll side){
ll sz=n/side;
ll wh=0,bl=side*side*((sz*sz+1)>>1);
for(ll i=0;i<m;i++){
ll block_x=rect[i].x/side;
ll block_y=rect[i].y/side;
if((block_x+block_y)&1)wh++;
else bl--;
}
return min(wh+bl,n*n-wh-bl);
}
int main(){
scanf("%lld%lld",&n,&m);
for(ll 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=solve(1);
for(ll i=2;i*i<=n;i++)if(n%i==0)res=min(res,min(solve(i),solve(n/i)));
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... |