Advertisement
Josif_tepe

Untitled

Jun 6th, 2023
782
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.25 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <stack>
  4. #include <cstring>
  5. using namespace std;
  6. int m ,k;
  7. int n;
  8. long long x;
  9. class node{
  10. public:
  11.     node *a, *b;
  12.     long long bitmask;
  13.     node(){
  14.         a = NULL;
  15.         b = NULL;
  16.         bitmask = 0;
  17.     }
  18. };
  19. int ret;
  20. string curr;
  21. void rek(int at, int depth, node *tmp){
  22.     tmp -> bitmask |= x;
  23.     int popcount = __builtin_popcount(tmp -> bitmask);
  24.     if(popcount == n && depth > ret){
  25.         ret = depth;
  26.     }
  27.     if(at == (int)curr.size() || depth > 60){
  28.         return;
  29.     }
  30.     if(curr[at] == 'a'){
  31.         if(tmp -> a == NULL){
  32.             tmp -> a = new node();
  33.         }
  34.         rek(at + 1, depth + 1, tmp -> a);
  35.     }
  36.     else{
  37.         if(tmp -> b == NULL){
  38.             tmp -> b = new node();
  39.         }
  40.         rek(at + 1, depth + 1, tmp -> b);
  41.     }
  42. }
  43. int main(int argc, const char * argv[]) {
  44.     ios_base::sync_with_stdio(false);
  45.     cin >> n;
  46.     string s[6];
  47.     node *root = new node();
  48.     for(int i =0; i < n; i ++){
  49.         cin >> s[i];
  50.     }
  51.     for(int i =0; i < n; i ++){
  52.         curr = s[i];
  53.         x = (1 << i);
  54.         for(int j =0; j < s[i].size(); j ++){
  55.             rek(j, 0, root);
  56.         }
  57.     }
  58.     cout << ret << endl;
  59.     return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement