-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathScore After Flipping Matrix.cpp
74 lines (72 loc) · 1.63 KB
/
Score After Flipping 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
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
class Solution {
public:
int matrixScore(vector<vector<int>>& A) {
int n = A.size();
int m = A[0].size();
int ans = 0,t=1;
// int count=1;
// int t=1;
for(int i=1;i<m;i++)
{
t=t*2;
}
for(int i=0;i<n;i++)
{
if(A[i][0]==0)
{
for(int j=0;j<m;j++)
{
if(A[i][j]==1)
{
A[i][j]=0;
}
else
{
A[i][j]=1;
}
}
}
}
for(int i=1;i<m;i++)
{
int zero=0;
for(int j=0;j<n;j++)
{
if(A[j][i]==0)
zero++;
}
if(zero>n/2)
{
for(int j=0;j<n;j++)
{
if(A[j][i]==0)
{
A[j][i]=1;
}
else
{
A[j][i]=0;
}
}
}
}
for(int i=0;i<n;i++)
{
int p=t;
{
for(int j=0;j<m;j++)
{
if(A[i][j]==1)
{
ans+=p;
p=p/2;
}
else
p=p/2;
}
}
// cout<<ans<<endl;
}
return ans;
}
};