Advertisement
Fshl0

dwdwd

Apr 29th, 2022
645
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.13 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define F first
  3. #define S second
  4. #define pb push_back
  5. #define mp make_pair
  6.  
  7. using namespace std;
  8. typedef long long ll;
  9. typedef pair <ll, ll> pii;
  10.  
  11. #include <ext/pb_ds/assoc_container.hpp>
  12. #include <ext/pb_ds/tree_policy.hpp>
  13. using namespace __gnu_pbds;
  14.  
  15. #define ordered_set tree<pair<ll,int>, null_type,less<pair<ll,int>>, rb_tree_tag,tree_order_statistics_node_update>
  16.  
  17. const int INF = 1e7;
  18. const ll llINF = 1e17;
  19. const int mxN = 2e5 + 9;
  20. const int mxM = 1e5 + 9;
  21. const int MOD = 1e9 + 7;
  22. const double pi = acos (-1);
  23.  
  24. int rand(int x, int y) {
  25.     static mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  26.     return uniform_int_distribution<int>(x, y)(rng);
  27. }
  28.  
  29. void setIO (string s) {
  30.     freopen ((s + ".in").c_str(), "r", stdin);
  31.     freopen ((s + ".out").c_str(), "w", stdout);
  32.    
  33.     return;
  34. }
  35.  
  36. int n, m, p;
  37.  
  38. string getS (ll x) {
  39.     string s = "";
  40.     for (int i = 0; i < m; i++)
  41.         s += ((1 << i) & x) ? "1" : "0";
  42.    
  43.     return s;
  44. }
  45.  
  46. void solve () {
  47.     cin >> n >> m >> p;
  48.    
  49.     vector <ll> mask (n + 1, 0);
  50.     for (int i = 1; i <= n; i++) {
  51.         string s;
  52.         cin >> s;
  53.        
  54.         for (int j = 0; j < (int) s.length(); j++) {
  55.             if (s[j] == '1')
  56.                 mask[i] |= (1 << j);
  57.         }
  58.     }
  59.    
  60.     ll res = 0;
  61.     for (int rep = 0; rep < 50; rep++) {
  62.         ll x = mask[rand (1, n)];
  63.        
  64.         vector <ll> tmpMask (n + 1, 0);
  65.         for (int i = 1; i <= n; i++) {
  66.            
  67.             int k = 0;
  68.             for (int j = 0; j < m; j++) {
  69.                 if ((x & (1 << j)) == 0)
  70.                     continue;
  71.                
  72.                 if (mask[i] & (1 << j))
  73.                     tmpMask[i] |= (1 << k);
  74.                 k++;
  75.             }
  76.         }
  77.        
  78.         vector <int> sup (1 << (p + 1), 0);
  79.         for (int i = 1; i <= n; i++)
  80.             sup[tmpMask[i]]++;
  81.        
  82.         for (int i = 0; i < p; i++) {
  83.             for (int msk = 0; msk < (1 << i); msk++) {
  84.                 if ((msk & (1 << i)) == 0)
  85.                     sup[msk] += sup[msk ^ (1 << i)];
  86.             }
  87.         }
  88.        
  89.         ll best = 0;
  90.         for (int y = x; y > 0; y = (y - 1) & x) {
  91.             if (sup[y] >= ((n + 1) / 2) && __builtin_popcount(y) > __builtin_popcount(best)) {
  92.                 best = y;
  93.             }
  94.         }
  95.        
  96.         int k = 0;
  97.         ll unCompressed = 0;
  98.        
  99.         for (int i = 0; i < m; i++) {
  100.             if ((x & (1 << i)) == 0)
  101.                 continue;
  102.                
  103.             if ((1 << k) & best)    
  104.                 unCompressed |= (1 << i);
  105.             k++;
  106.         }
  107.        
  108.         if (__builtin_popcount(unCompressed) > __builtin_popcount (res))
  109.             res = unCompressed;
  110.     }
  111.    
  112.     cout << getS(res) << "\n";
  113.     return;
  114. }
  115.  
  116. int main () {
  117.     int t = 1;
  118.     //cin >> t;
  119.    
  120.     //ios_base::sync_with_stdio (0);
  121.     //cin.tie (0);
  122.    
  123.     //setIO ("billboard");
  124.     //preCalc ();
  125.     while (t--) {
  126.         //initialize common variables
  127.        
  128.         //go solve
  129.         solve ();
  130.     }
  131.    
  132.     return 0;
  133. }
  134.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement