fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. typedef long long ll;
  6. typedef pair<int, int> ii;
  7.  
  8. const int INF = 1e9;
  9. const ll LINF = 1e18;
  10.  
  11. template<typename T>
  12. void minimize(T& a, const T& b) {
  13. if (b < a) a = b;
  14. }
  15.  
  16. const int N = 2e4 + 5;
  17.  
  18. int n, k;
  19. int mask[N];
  20.  
  21. int hamming(int a, int b) {
  22. return __builtin_popcount(a ^ b);
  23. }
  24.  
  25. int main() {
  26. ios::sync_with_stdio(false);
  27. cin.tie(nullptr);
  28. cin >> n >> k;
  29. for (int i = 0; i < n; i++) {
  30. string s; cin >> s;
  31. for (int j = 0; j < k; j++) {
  32. mask[i] |= (1 << j) * (s[j] - '0');
  33. }
  34. }
  35.  
  36. int ans = INF;
  37. for (int i = 0; i + 1 < n; i++) {
  38. for (int j = i + 1; j < n; j++) {
  39. minimize(ans, hamming(mask[i], mask[j]));
  40. }
  41. }
  42.  
  43. cout << ans << '\n';
  44. }
Success #stdin #stdout 0.01s 5276KB
stdin
5 6
110111
001000
100001
101000
101110
stdout
1