Advertisement
Ahmed_Negm

Untitled

Oct 4th, 2022
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.09 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #include <ext/pb_ds/assoc_container.hpp>
  3. #include <ext/pb_ds/tree_policy.hpp>
  4. using namespace std;
  5. using namespace __gnu_pbds;
  6. #define ll long long
  7. #define ull unsigned long long
  8. #define nl '\n'
  9. #define sz(x) int(x.size())
  10. #define all(x) x.begin(),x.end()
  11. #define rall(s)  s.rbegin(), s.rend()
  12. #define getline(s) getline(cin>>ws,s)
  13. #define ceill(n, m) (((n) / (m)) + ((n) % (m) ? 1 : 0))
  14. #define pi  3.141592653589793
  15. #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
  16. #define multi_ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
  17.  
  18.  
  19. void Fast_IO(){
  20.     ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  21. // freopen("filename.in", "r", stdin);
  22. // freopen("filename.txt", "w", stdout);
  23. #ifndef ONLINE_JUDGE
  24.     freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  25. #endif
  26. }
  27.  
  28. int dx[8] = { 2, 1, -1, -2, -2, -1, 1, 2 };
  29. int dy[8] = { 1, 2, 2, 1, -1, -2, -2, -1 };
  30. unordered_map<char,bool>omar,sanad;
  31. vector<char> alpha;
  32. vector<ll> score;
  33. double omar_score =0;
  34. void rec(ll fir =0,ll sec=0,int idx=0){
  35.     if(idx == sz(alpha)){
  36.         omar_score+=(fir>sec);
  37.         return;
  38.     }
  39.     if(omar[alpha[idx]]==1){
  40.         rec(fir+score[idx],sec,idx+1);
  41.     }
  42.     if(sanad[alpha[idx]]==1) {
  43.         rec(fir, sec + score[idx], idx + 1);
  44.     }
  45.     if(!omar[alpha[idx]] and !sanad[alpha[idx]]){
  46.         rec(fir + score[idx], sec, idx + 1);
  47.         rec(fir, sec + score[idx], idx + 1);
  48.     }
  49. }
  50.  
  51.  
  52.  
  53. void solve(){
  54.     ll n; cin>>n;
  55.     alpha.resize(n);
  56.     score.resize(n);
  57.     for(auto&i:alpha)cin>>i;
  58.     for(auto&i:score)cin>>i;
  59.     ll m; cin>>m;
  60.     for(int i=0; i<m; i++){
  61.         char c; cin>>c;
  62.         omar[c]=1;
  63.     }
  64.     ll k; cin>>k;
  65.     for(int i=0; i<k; i++){
  66.         char c; cin>>c;
  67.         sanad[c]=1;
  68.     }
  69.  
  70.     rec();
  71.     cout<<fixed<<setprecision(9);
  72.     cout<<omar_score/(1<<n/2)<<nl;
  73.  
  74.  
  75.  
  76. }
  77.  
  78. int main(){
  79.     Fast_IO();
  80.     int t =1;
  81. //cin>>t;
  82.     while(t--){
  83.         solve();
  84.     }
  85.     return 0;
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement