Advertisement
yuhung94

Untitled

Dec 14th, 2022 (edited)
534
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.38 KB | None | 0 0
  1. #pragma GCC optimize("Ofast,no-stack-protector")
  2. #include<bits/stdc++.h>
  3. //#define int long long
  4. #define quick ios::sync_with_stdio(0);cin.tie(0);
  5. #define rep(x,a,b) for(int x=a;x<=b;x++)
  6. #define repd(x,a,b) for(int x=a;x>=b;x--)
  7. #define F first
  8. #define S second
  9. #define all(x) x.begin(),x.end()
  10. #define mp make_pair
  11. #define eb emplace_back
  12. #define sz(x) (int)(x.size())
  13. #define lowbit(x) (x&-x)
  14. using namespace std;
  15. typedef pair<int,int> pii;
  16. typedef complex<int> P;
  17. #define X real()
  18. #define Y imag()
  19. void debug(){
  20.     cout<<"\n";
  21. }
  22. template<class T,class ...U>
  23. void debug(T a,U ...b){
  24.     cout<<a<<" ",debug(b...);
  25. }
  26. const int N=2e5+7;
  27. const int INF=1e18;
  28. bool p1(const string&v1,const string&v2){
  29.     unordered_map<char,bool> m;
  30.     for(char i:v1) m[i]=true;
  31.     for(char i:v2){
  32.         if(m.count(i)) return false;
  33.     }
  34.     return true;
  35. }
  36. bool p2(const string&v1,const string&v2){
  37.     if(sz(v1)==sz(v2)) return false;
  38.     unordered_map<char,bool> m;
  39.     for(char i:v2) m[i]=true;
  40.     for(char i:v1){
  41.         if(!m.count(i)) return false;
  42.     }
  43.     return true;
  44. }
  45. bool p3(const string&v1,const string&v2){
  46.     return p2(v2,v1);
  47.  
  48. }
  49. bool eq(const string&v1,const string&v2){
  50.     if(sz(v1)!=sz(v2)) return false;
  51.     unordered_map<char,bool> m;
  52.     for(char i:v2) m[i]=true;
  53.     for(char i:v1){
  54.         if(!m.count(i)) return false;
  55.     }
  56.     return true;
  57. }
  58. bool p4(const string&v1,const string&v2){
  59.     return !p1(v1,v2)&&!p2(v1,v2)&&!p3(v1,v2)&&!eq(v1,v2);
  60. }
  61. string s[N];
  62. int cntp5(const string&x,int n){
  63.     int l=sz(x);
  64.     rep(i,0,n-1){
  65.         rep(j,i+1,n-1){
  66.             if(p4(s[i],s[j])){
  67.                 return 0;
  68.             }
  69.         }
  70.     }
  71.     int ans=0;
  72.     rep(S,0,(1<<l)-1){
  73.         string x1;
  74.         string x2;
  75.         rep(i,0,l-1){
  76.             if((1<<i)&S) x1+=x[i];
  77.             else x2+=x[i];
  78.         }
  79.         ans++;
  80.         rep(i,0,n-1){
  81.             if(p4(x1,s[i])||p4(x2,s[i])){
  82.                 ans--;break;
  83.             }
  84.  
  85.         }
  86.  
  87.     }
  88.     return ans;
  89. }
  90.  
  91. signed main(){
  92.     quick
  93.  
  94.     int n;
  95.     cin>>n;
  96.     string x;
  97.     cin>>x;
  98.     rep(i,0,n-1){
  99.         cin>>s[i];
  100.     }
  101.     int P1,P2,P3,P4;
  102.     P1=P2=P3=P4=0;
  103.     rep(i,0,n-1){
  104.         P1+=p1(s[i],x);
  105.         P2+=p2(x,s[i]);
  106.         P3+=p3(x,s[i]);
  107.         P4+=p4(s[i],x);
  108.     }
  109.     cout<<P1<<" "<<P2<<" "<<P3<<" "<<P4<<" "<<cntp5(x,n)<<"\n";
  110.  
  111. }
  112.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement