forked from DionysiosB/CodeForces
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1720C-Corners.cpp
More file actions
32 lines (27 loc) · 931 Bytes
/
Copy path1720C-Corners.cpp
File metadata and controls
32 lines (27 loc) · 931 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
#include <iostream>
#include <vector>
int main(){
std::ios_base::sync_with_stdio(false);
long t; std::cin >> t;
while(t--){
long n, m; std::cin >> n >> m;
std::vector<std::string> v(n); for(long row = 0; row < n; row++){std::cin >> v[row];}
long ones(0);
for(long row = 0; row < n; row++){
for(long col = 0; col < m; col++){
ones += v[row][col] - '0';
}
}
long mn(5);
for(long row = 0; row < n - 1; row++){
for(long col = 0; col < m - 1; col++){
long cur = v[row][col] + v[row][col + 1] + v[row + 1][col] + v[row + 1][col + 1] - 4 * '0';
if(!cur){continue;}
long tst = (cur > 2) ? (cur - 1) : 1;
mn = (mn < tst) ? mn : tst;
}
}
long ans = ones ? (1 + ones - mn) : 0;
std::cout << ans << std::endl;
}
}