Skip to content

Commit 409661b

Browse files
authored
Create Counting subgrids
1 parent 4faa791 commit 409661b

File tree

1 file changed

+138
-0
lines changed

1 file changed

+138
-0
lines changed

Bit Manipulations/Counting subgrids

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
//Author: Fuadul Hasan([email protected])
2+
//BSMRSTU,Gopalganj
3+
//#include<bits/stdc++.h>
4+
#define _USE_MATH_DEFINES
5+
#include <set>
6+
#include <map>
7+
#include <list>
8+
#include <queue>
9+
#include <stack>
10+
#include <cmath>
11+
#include <ctime>
12+
#include <cstdio>
13+
#include <string>
14+
#include <vector>
15+
#include <bitset>
16+
#include <random>
17+
#include <cassert>
18+
#include <cstring>
19+
#include <sstream>
20+
#include <complex>
21+
#include <numeric>
22+
#include <iostream>
23+
#include <algorithm>
24+
#include <functional>
25+
#include <unordered_set>
26+
#include <unordered_map>
27+
using namespace std;
28+
29+
//debug..........
30+
#define error(args...) {vector<string>_v=split(#args,',');err(_v.begin(),args);cout<<endl;}
31+
vector<string> split(const string &s, char c) {vector<string>v; stringstream ss(s); string x;while (getline(ss, x, c))v.emplace_back(x); return move(v);} void err(vector<string>::iterator it) {}
32+
template<typename T, typename... Args>void err(vector<string>::iterator it, T a, Args...args) {cout << it->substr((*it)[0] == ' ', it->length()) << " = " << a << " "; err(++it, args...);}
33+
34+
//............ignore it..................//
35+
#define F first
36+
#define S second
37+
38+
#define Pi atan(1)*4
39+
#define mp make_pair
40+
#define pb push_back
41+
const int M = 1e9 + 7;
42+
43+
#define ld long double
44+
#define ll long long int
45+
#define happy cin.tie(0);
46+
47+
#define point(x) cout<<fixed<<setprecision(x)
48+
int length(string s){return (int)s.size();}
49+
50+
#define mem(a) memset(a , 0 ,sizeof a)
51+
#define memn(a) memset(a , -1 ,sizeof a)
52+
53+
#define coding ios::sync_with_stdio(false);
54+
#define Unique(c) (c).resize(unique(all(c))-(c).begin())
55+
#define vout(v) for (auto z: v) cout << z << " "; cout << endl;
56+
57+
int length(long long x){int l = 0;for(long long i=x;i;i/=10)l++;return l;}
58+
int dx[8]= {1,0,-1,0,-1,-1,1,1};
59+
int dy[8]= {0,1,0,-1,-1,1,-1,1};
60+
61+
62+
#define rep(i,b,e) for(__typeof(e) i = (b) ; i != (e + 1) - 2 * ((b) > (e)) ; i += 1 - 2 * ((b) > (e)))
63+
64+
long long power(long long a,long long n){ll res = 1;while(n){if(n&1) res = ((res%M)*(a%M))%M;a = ((a%M)*(a%M))%M;n>>=1;}return res%M;}
65+
66+
#define Test cout<<"Case #"<<tc++<<": ";
67+
int tc = 1;
68+
69+
inline void read(std::vector<int> &v){for(int i=0;i<(int)v.size();i++){cin>>(v[i]);}}
70+
inline void readl(std::vector<ll> &v){for(int i=0;i<(int)v.size();i++){cin>>(v[i]);}}
71+
72+
template<class T> bool remin(T& a, const T& b) { return a > b ? a = b, 1 : 0; }
73+
template<class T> bool remax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
74+
75+
inline void read(int v[],int n){for(int i=0;i<n;i++){cin>>(v[i]);}}
76+
inline void readl(ll v[],int n){for(int i=0;i<n;i++){cin>>(v[i]);}}
77+
78+
inline int add(int a, int b, int mod) {a += b ; return a >= mod ? a - mod : a ;}
79+
inline int sub(int a, int b, int mod) {a -= b ; return a < 0 ? a + mod : a ;}
80+
inline int mul(int a, int b, int mod) {return (ll)a * b % mod ;}
81+
82+
#define pr pair<int, int>
83+
#define vpr vector<pr>
84+
#define vi std::vector<int>
85+
#define vll std::vector<ll>
86+
#define all(n) n.begin(),n.end()
87+
88+
89+
const int Inf = (int)2e9 + 5;
90+
const ll Lnf = (ll)2e18 + 5;
91+
const int N = 5e5 + 5;
92+
const int NN = 1e6 + 5;
93+
94+
95+
96+
int solve()
97+
{
98+
99+
//Test
100+
101+
//counting subgrids
102+
103+
int n;
104+
cin>>n;
105+
106+
int a[n][n];
107+
for(int i=0;i<n;i++){
108+
for(int j=0;j<n;j++){
109+
cin>>a[i][j];
110+
}
111+
}
112+
113+
int res = 0;
114+
for(int i=0;i<n;i++){
115+
for(int j=i+1;j<n;j++){
116+
int cnt = 0;
117+
for(int k=0;k<n;k++){
118+
if(a[i][k] == 1 and a[j][k] == 1)cnt++;
119+
}
120+
res += (cnt*(cnt-1))/2;
121+
}
122+
}
123+
124+
cout<<res<<endl;
125+
126+
return 0;
127+
//error();
128+
}
129+
int main(){
130+
131+
happy coding
132+
int test = 1;
133+
//cin>>test;
134+
while (test--)solve();return 0;
135+
}
136+
137+
138+

0 commit comments

Comments
 (0)