-
Notifications
You must be signed in to change notification settings - Fork 0
/
01368.cpp
47 lines (36 loc) · 1.05 KB
/
01368.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
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
ll t; cin >> t;
while(t--){
ll m, n; cin >> m >> n;
char res[n]; ll Max[n] = {0};
ll sum = 0;
unordered_map<char,ll> f[n];
for(ll p = 0; p < m; p++){
string str; cin >> str;
for(ll i = 0; i < n; i++){
++f[i][str[i]];
if(f[i][str[i]] > Max[i]){
Max[i] = f[i][str[i]];
res[i] = str[i];
}
else if(f[i][str[i]] == Max[i]){
res[i] = min(res[i], str[i]);
}
}
}
for(ll i = 0; i < n; i++){
sum += m - Max[i];
}
for(ll i = 0; i < n; i++) cout << res[i];
cout << "\n";
cout << sum << "\n";
}
return 0;
}