-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathA. Binary Matrix.cpp
More file actions
51 lines (42 loc) · 858 Bytes
/
A. Binary Matrix.cpp
File metadata and controls
51 lines (42 loc) · 858 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
40
41
42
43
44
45
46
47
48
49
50
51
#include <iostream>
#include <vector>
using namespace std;
void solve()
{
int n, m;
cin >> n >> m;
vector<int> row_xor(n, 0), col_xor(m, 0);
for (int i = 0; i < n; ++i)
{
string row;
cin >> row;
for (int j = 0; j < m; ++j)
{
int value = row[j] - '0';
row_xor[i] ^= value;
col_xor[j] ^= value;
}
}
int row_odd = 0, col_odd = 0;
for (int i = 0; i < n; ++i)
{
if (row_xor[i] == 1) row_odd++;
}
for (int j = 0; j < m; ++j)
{
if (col_xor[j] == 1) col_odd++;
}
cout << max(row_odd, col_odd) << "\n";
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--)
{
solve();
}
return 0;
}