-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1285.cpp
More file actions
48 lines (47 loc) · 1.04 KB
/
1285.cpp
File metadata and controls
48 lines (47 loc) · 1.04 KB
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
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define ft first
#define sd second
#define all(x) (x).begin(), (x).end()
using namespace std;
using vb = vector<bool>;
using vvb = vector<vb>;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n;
string s;
cin>>n;
vvb map(n,vb(n));
for(int i=0;i<n;i++){
cin>>s;
for(int j=0;j<n;j++){
map[i][j] = (s[j]=='T'?true:false);
}
}
auto origin = map;
int ans = INF;
for(int k=0;k<(1<<n);k++){
map = origin;
int cur = k;
for(int j=n-1;j>=0;j--){
if(cur-(1<<j)>=0){
cur-=(1<<j);
for(int i=0;i<n;i++){
map[i][j] = !map[i][j];
}
}
}
int val=0;
for(int i=0;i<n;i++){
int cnt=0;
for(int j=0;j<n;j++){
if(map[i][j])
cnt++;
}
val+=min(cnt , n-cnt);
}
ans = min(ans , val);
}
cout<<ans;
}