-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1676C.cpp
More file actions
52 lines (40 loc) · 1.02 KB
/
Copy path1676C.cpp
File metadata and controls
52 lines (40 loc) · 1.02 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
49
50
51
52
#include <bits/stdc++.h>
#define pb push_back
#define f(i, x, n) for(int i = x; i < n; i++)
#define endl '\n'
#define optimize() ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
int distFinder(string a, string b);
int main() {
optimize();
int t;
cin >> t;
while (t--) {
int n, m;
cin >> n >> m;
string arr[n];
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
int minDist = INT_MAX;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (i == j) {
continue;
} else {
if (distFinder(arr[i], arr[j]) < minDist) {
minDist = distFinder(arr[i], arr[j]);
}
}
}
}
cout << minDist << endl;
}
}
int distFinder(string a, string b) {
int res = 0;
for (int i = 0; i < a.size(); i++) {
res += abs(a[i] - b[i]);
}
return res;
}