CC: CAKECUT ( BITSET Logic )

CC: CAKECUT ( BITSET Logic )

///==================================================///
/// HELLO WORLD !! ///
/// IT'S ME ///
/// BISHAL GAUTAM ///
/// [ bsal.gautam16@gmail.com ] ///
///==================================================///
#include<bits/stdc++.h>
#define X first
#define Y second
#define mpp make_pair
#define nl printf("\n")
#define SZ(x) (int)(x.size())
#define pb(x) push_back(x)
#define pii pair<int,int>
#define pll pair<ll,ll>
///---------------------
#define S(a) scanf("%d",&a)
#define P(a) printf("%d",a)
#define SL(a) scanf("%lld",&a)
#define S2(a,b) scanf("%d%d",&a,&b)
#define SL2(a,b) scanf("%lld%lld",&a,&b)
///------------------------------------
#define all(v) v.begin(),v.end()
#define CLR(a) memset(a,0,sizeof(a))
#define SET(a) memset(a,-1,sizeof(a))
#define fr(i,a,n) for(int i=a;i<=n;i++)
using namespace std;
typedef long long ll;

/// Digit 0123456789012345678 ///
#define MX 1502
#define inf 2000000010
#define MD 1000000007
#define eps 1e-9
///===============================///

int r,c,x,dp[MX][MX];
bitset<1501>Row[MX];
ll Sm(ll x){
return (x*(x-1))/2LL;
}
int main() {
S2(r,c);
Row[0].reset();
ll sm=0;
fr(i,1,r) {
Row[i].reset();
fr(j,1,c) {
scanf("%1d",&x);
dp[i][j]=(dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1]+x)%2;
///Cumulative Sum from begining storing only MOD values;
if( dp[i][j] ) Row[i].set(j);
}
fr(j,0,i-1) {
bitset<1501>xr=Row[i]^Row[j];
int on=xr.count();///total Ones
int zr=c-on+1;///Total Zeros+1 for
sm+=Sm(on);
sm+=Sm(zr);
}
}
printf("%lld\n",sm);

return 0;
}

Comments

Popular posts from this blog

HackerEarth: City and Campers 2 (DSU-UnionFind)

Two Pointers Technique & Binary Search For Beginners

Problem : Codeforces Round #406 (Div. 1) B [ Legacy ]( Dijakstra, Segment tree)