Advertisement
yuhung94

2225 . C. 樣本解析

Dec 14th, 2022
471
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.39 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 ans=0;
  63. void dfs(const string&x,string x1,string x2,int st,int n,int l){
  64.     rep(i,0,n-1){
  65.         if(p4(x1,s[i])||p4(x2,s[i])) return ;
  66.     }
  67.     if(st>=l){
  68.         ans++;
  69.         return ;
  70.     }
  71.     dfs(x,string(x1+x[st]),x2,st+1,n,l);
  72.     dfs(x,x1,string(x2+x[st]),st+1,n,l);
  73. }
  74.  
  75. int cntp5(const string&x,int n){
  76.     int l=sz(x);
  77.     rep(i,0,n-1){
  78.         rep(j,i+1,n-1){
  79.             if(p4(s[i],s[j])){
  80.                 return 0;
  81.             }
  82.         }
  83.     }
  84.     ans=0;
  85.     dfs(x,"","",0,n,l);
  86.     return ans;
  87. }
  88.  
  89. signed main(){
  90.     quick
  91.  
  92.     int n;
  93.     cin>>n;
  94.     string x;
  95.     cin>>x;
  96.     rep(i,0,n-1){
  97.         cin>>s[i];
  98.     }
  99.     int P1,P2,P3,P4;
  100.     P1=P2=P3=P4=0;
  101.     rep(i,0,n-1){
  102.         P1+=p1(s[i],x);
  103.         P2+=p2(x,s[i]);
  104.         P3+=p3(x,s[i]);
  105.         P4+=p4(s[i],x);
  106.     }
  107.     cout<<P1<<" "<<P2<<" "<<P3<<" "<<P4<<" "<<cntp5(x,n)<<"\n";
  108.  
  109. }
  110.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement