Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #include <ext/pb_ds/assoc_container.hpp>
- #include <ext/pb_ds/tree_policy.hpp>
- using namespace std;
- using namespace __gnu_pbds;
- #define ll long long
- #define ull unsigned long long
- #define nl '\n'
- #define sz(x) int(x.size())
- #define all(x) x.begin(),x.end()
- #define rall(s) s.rbegin(), s.rend()
- #define getline(s) getline(cin>>ws,s)
- #define ceill(n, m) (((n) / (m)) + ((n) % (m) ? 1 : 0))
- #define pi 3.141592653589793
- #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
- #define multi_ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
- void Fast_IO(){
- ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
- // freopen("filename.in", "r", stdin);
- // freopen("filename.txt", "w", stdout);
- #ifndef ONLINE_JUDGE
- freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
- #endif
- }
- int dx[8] = { 2, 1, -1, -2, -2, -1, 1, 2 };
- int dy[8] = { 1, 2, 2, 1, -1, -2, -2, -1 };
- unordered_map<char,bool>omar,sanad;
- vector<char> alpha;
- vector<ll> score;
- double omar_score =0;
- void rec(ll fir =0,ll sec=0,int idx=0){
- if(idx == sz(alpha)){
- omar_score+=(fir>sec);
- return;
- }
- if(omar[alpha[idx]]==1){
- rec(fir+score[idx],sec,idx+1);
- }
- if(sanad[alpha[idx]]==1) {
- rec(fir, sec + score[idx], idx + 1);
- }
- if(!omar[alpha[idx]] and !sanad[alpha[idx]]){
- rec(fir + score[idx], sec, idx + 1);
- rec(fir, sec + score[idx], idx + 1);
- }
- }
- void solve(){
- ll n; cin>>n;
- alpha.resize(n);
- score.resize(n);
- for(auto&i:alpha)cin>>i;
- for(auto&i:score)cin>>i;
- ll m; cin>>m;
- for(int i=0; i<m; i++){
- char c; cin>>c;
- omar[c]=1;
- }
- ll k; cin>>k;
- for(int i=0; i<k; i++){
- char c; cin>>c;
- sanad[c]=1;
- }
- rec();
- cout<<fixed<<setprecision(9);
- cout<<omar_score/(1<<n/2)<<nl;
- }
- int main(){
- Fast_IO();
- int t =1;
- //cin>>t;
- while(t--){
- solve();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement