Submission #334486

# Submission time Handle Problem Language Result Execution time Memory
334486 2020-12-09T08:47:31 Z juggernaut Chessboard (IZhO18_chessboard) C++14
Compilation error
0 ms 0 KB
#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,pref_bl[100005],pref_wh[100005];
ll range_bl(ll l,ll r){
    if(l)return pref_bl[r]-pref_bl[l-1];
    return pref_bl[r];
}
ll range_wh(ll l,ll r){
    if(l)return pref_wh[r]-pref_wh[l-1];
    return pref_wh[r];
}
ll calc_wh(ll x,ll y,ll x2,ll y2){
    ll ans=0;
    ans=(x2-x+1)*(y2-y+1)-calc_bl(x,y,x2,y2);
    return ans;
}
ll calc_bl(ll x,ll y,ll x2,ll y2){
    ll ans=0;
    ans+=range_bl(x,x2)*range_bl(y,y2);
    ans+=range_wh(x,x2)*range_wh(y,y2);
    return ans;
}
ll solve(ll side){
    ll sz=n/side;
    ll wh=0,bl=side*side*((sz*sz+1)>>1);
    pref_bl[0]=1;
    pref_wh[0]=0;
    for(ll i=1;i<n;i++)
        pref_wh[i]=pref_wh[i-1]+((i/side)&1),pref_bl[i]=i+1-pref_wh[i];
    for(ll i=0;i<m;i++){
        wh+=calc_wh(rect[i].x,rect[i].y,rect[i].x2,rect[i].y2);
        bl-=calc_bl(rect[i].x,rect[i].y,rect[i].x2,rect[i].y2);
    }
    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

chessboard.cpp: In function 'll calc_wh(ll, ll, ll, ll)':
chessboard.cpp:21:27: error: 'calc_bl' was not declared in this scope; did you mean 'calc_wh'?
   21 |     ans=(x2-x+1)*(y2-y+1)-calc_bl(x,y,x2,y2);
      |                           ^~~~~~~
      |                           calc_wh
chessboard.cpp: In function 'int main()':
chessboard.cpp:44:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   44 |     scanf("%lld%lld",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~~~~~
chessboard.cpp:45:29: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   45 |     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();
      |                        ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~