-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEven_Matrix.cpp
38 lines (35 loc) · 900 Bytes
/
Even_Matrix.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <iostream>
#include <vector>
using namespace std;
int t, n;
void solve(){
cin >> n;
vector< vector<int> > mat(n + 1, vector<int>(n + 1, 0));
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
cin >> mat[i][j];
mat[i][j] += (mat[i-1][j-1]-mat[i][j-1]-mat[i-1][j]);
}
}
int res = 0;
for(int i1 = 1; i1 <= n; i1++){
for(int i2 = i1; i2 <= n; i2++){
int cnt = 0, sum = 0;
for(int j = 1; j <= n; j++){
sum += (mat[i2][j] - mat[i1 - 1][j] - mat[i2][j-1] + mat[i1 - 1][j-1]);
if(sum % 2==0) cnt++;
}
res += (cnt + cnt*(cnt-1)/2 + (n - cnt)*(n-cnt-1)/2);
}
}
cout << res << endl;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> t;
while(t--){
solve();
}
return 0;
}