fork download
  1.  
  2.  
  3. #include <bits/stdc++.h>
  4. #include <string.h>
  5. using namespace std;
  6. #define ll long long
  7.  
  8. void solve(){
  9. ll n,x,y;cin>>n>>x>>y;
  10. string a,b;cin>>a>>b;map<char,int>mp;
  11. for(auto p:a){mp[p]++;}
  12. ll ans=0;
  13. for(ll i=0;i<n;i++){int p=0;
  14. if(a[i]==b[i]){p=1;}
  15. if(a[i]!=b[i]){
  16. if(mp[b[i]]==0 || x>=2*y){ans+=y;mp[a[i]]--;p=1;}
  17. else{for(int j=i+1;j<n;j++){if((a[j]==b[i]) && (a[i]==b[j])){ans+=x;mp[a[j]]--;mp[a[i]]--;a[j]=b[j];p=1;break;}}}
  18. if(p==0){ans+=y;}
  19. }
  20. }cout<<ans<<endl;
  21. }
  22.  
  23. int main() {
  24. ios_base::sync_with_stdio(false);
  25. cin.tie(NULL);
  26. cout.tie(NULL);
  27. int t;cin>>t;
  28. while(t--)
  29. solve();
  30. return 0;
  31. }
Success #stdin #stdout 0.01s 5296KB
stdin
3
3 1 2
aaa
aaa
4 6 2
abcd
badc
4 3 2
abcd
badc
stdout
0
8
6