-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathToggle.cpp
76 lines (55 loc) · 1.47 KB
/
Toggle.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
A binary matrix of nxm was given, you have to toggle any column k number of times so that you can get the maximum
number of rows having all 1’s.
for eg, n=3, m=3,
1 0 0
1 0 1
1 0 0
if k=2, then we will toggle column 2 and 3 once and we will get rows 1 and 3 with 1 1 1 and 1 1 1 i.e. all 1’s so
answer is 2 as there are 2 rows with all 1’s.
if k=3, then we will toggle column 2 thrice and we will get row 2 with 1 1 1 i.e. all 1’s so answer is 1 as there
is 1 row with all 1’s.
*/
#include<iostream>
#include<vector>
#include<string>
#include<map>
using namespace std;
int main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int n,m,k,ans=-1000000;
cin>>n>>m>>k;
vector<vector<int> > mat(n,vector<int>(m,0));
map<string,int>mp;
string str;
for(int i=0;i<n;i++)
{
str="";
for(auto j=0;j<m;j++)
{
cin>>mat[i][j];
str+=to_string(mat[i][j]);
}
mp[str]++;
}
for(auto i: mp)
{
int zeros = 0;
for(auto j=0;j<i.first.size();j++)
{
if(i.first[j]=='0')
{
zeros++;
}
}
if(zeros<=k && (k-zeros)%2==0)
{
ans = max(ans,i.second);
}
}
cout<<ans<<endl;
}