-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpalindromic_path.cpp
More file actions
39 lines (33 loc) · 844 Bytes
/
palindromic_path.cpp
File metadata and controls
39 lines (33 loc) · 844 Bytes
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
39
#include<bits/stdc++.h>
using namespace std;
int t, n, m, field[31][31];
int myPath() {
// int cardinalidade = n + m - 1;
int secondsDiags[n + m][2] = {0};
int ans = 0;
for(int i = 0; i < n; ++i) {
for(int j = 0; j < m; ++j) {
secondsDiags[i + j][field[i][j]]++;
// cin >> field[i][j];
}
}
for(int i = 0; i < n + m - 1; ++i) {
int j = n + m - 2 - i;
if(i <= j) continue;
ans += min(secondsDiags[i][0] + secondsDiags[j][0], secondsDiags[i][1] + secondsDiags[j][1]);
}
return ans;
}
int main() {
cin >> t;
while(t--) {
cin >> n >> m;
for(int i = 0; i < n; ++i) {
for(int j = 0; j < m; ++j) {
cin >> field[i][j];
}
}
cout << myPath() << endl;
}
return 0;
}