1 solutions

  • 0
    @ 2026-7-28 16:17:16
    /*
     *                                                     __----~~~~~~~~~~~------___
     *                                    .  .   ~~//====......          __--~ ~~
     *                    -.            \_|//     |||\\  ~~~~~~::::... /~
     *                 ___-==_       _-~o~  \/    |||  \\            _/~~-
     *         __---~~~.==~||\=_    -_--~/_-~|-   |\\   \\        _/~
     *     _-~~     .=~    |  \\-_    '-~7  /-   /  ||    \      /
     *   .~       .~       |   \\ -_    /  /-   /   ||      \   /
     *  /  ____  /         |     \\ ~-_/  /|- _/   .||       \ /
     *  |~~    ~~|--~~~~--_ \     ~==-/   | \~--===~~        .\
     *           '         ~-|      /|    |-~\~~       __--~~
     *                       |-~~-_/ |    |   ~\_   _-~            /\
     *                            /  \     \__   \/~                \__
     *                        _--~ _/ | .-~~____--~-/                  ~~==.
     *                       ((->/~   '.|||' -_|    ~~-/ ,              . _||
     *                                  -_     ~\      ~~---l__i__i__i--~~_/
     *                                  _-~-__   ~)  \--______________--~~
     *                                //.-~~~-~_--~- |-------~~~~~~~~
     *                                       //.-~~~--\
     *                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     *
     *                               神兽保佑            永无BUG
     */
    
    /*
     * @Description: I want to be the weakest vegetable in the world!
     * @Author: I.Z.
     */
    #include<bits/stdc++.h>
    using namespace std;
    #define MOD         998244353
    #define speMOD      2933256077ll
    #define int         long long
    #define pii         pair<int,int>
    #define all(v)      v.begin(),v.end()
    #define pb          push_back
    #define REP(i,b,e)  for(int i=(b);i<(int)(e);++i)
    #define over(x)     {cout<<(x)<<endl;return;}
    #define lowbit(x)   ((x)&(-(x)))
    #define cntbit(x)   __builtin_popcount(x)
    #define rf(v)       shuffle(all(v),sd);
    #define deal(v)     sort(all(v));v.erase(unique(v.begin(),v.end()),v.end())
    #define lbound(v,x) lower_bound(all(v),x)-v.begin()
    mt19937 sd(random_device{}());
    int qpow(int a,int b,int m=MOD,int res=1){
    	a%=m;
    	while(b>0)res=(b&1)?(res*a%m):(res),a=a*a%m,b>>=1;
    	return res;
    }
    string YN(bool x,string Y="Yes",string N="No") {
    	if(x){
    		return Y;
    	} else {
    		return N;
    	}
    }
    int exgcd(int x,int y,int &a,int &b){
    	if(y==0){
    		a=1;b=0;
    		return x;
    	}
    	int d=exgcd(y,x%y,a,b);
    	int z=b;
    	b=a-b*(x/y);
    	a=z;
    	return d;
    }
    int _x_,_y_;
    inline int inverse(int x,int y=MOD){
    	exgcd(x,y,_x_,_y_);
    	return (_x_+y)%y;
    }
    int fac[2000005],inv[2000005];
    void init(int n){
    	fac[0]=inv[0]=1;
    	REP(i,1,n+1)fac[i]=fac[i-1]*i%MOD;
    	inv[n]=qpow(fac[n],MOD-2);
    	for(int i=n-1;i>=1;--i)inv[i]=inv[i+1]*(i+1)%MOD;
    }
    int binom(int x,int y){
    	return x<y||y<0? 0:fac[x]*inv[y]%MOD*inv[x-y]%MOD;
    }
    int n;
    int A,B,C;
    int dp[4000005];
    int s1[4000005],s2[4000005],lst[8000005];
    void Main() {
    	cin>>n>>A>>B>>C;
    	vector<int>s,t;
    	string S,T;
    	cin>>S>>T;
    	REP(i,0,n){
    		int c=(S[i]<=57? S[i]^48:S[i]-55);
    		REP(j,0,4)if((c>>(3-j))&1)s.pb(1);else s.pb(0);
    	}
    	REP(i,0,n){
    		int c=(T[i]<=57? T[i]^48:T[i]-55);
    		REP(j,0,4)if((c>>(3-j))&1)t.pb(1);else t.pb(0);
    	}
    	n*=4;
    	REP(i,0,n)s1[i+1]=s1[i]+(s[i]? i:0),s2[i+1]=s2[i]+(t[i]? i:0);
    	dp[0]=0;
    	REP(i,0,n*2+1)lst[i]=-1;
    	lst[n]=0;int sum=n;
    	REP(i,1,n+1){
    		if(s[i-1]==t[i-1])dp[i]=dp[i-1];
    		else if(!s[i-1])dp[i]=dp[i-1]+A;
    		else dp[i]=dp[i-1]+B;
    		sum+=s[i-1]-t[i-1];
    		if(lst[sum]!=-1){
    			int c=llabs(s1[i]-s1[lst[sum]]-s2[i]+s2[lst[sum]]);
    			if((__int128)(c)*C<=2e18)dp[i]=min(dp[i],dp[lst[sum]]+c*C);
    		}
    		lst[sum]=i;
    	}
    	cout<<dp[n]<<endl;
    }
    void TC() {
        int tc=1;
        cin>>tc;
    	while(tc--){
    		Main();
    		cout.flush();
    	}
    }
    signed main() {
    	freopen("a.in","r",stdin);
    	freopen("a.out","w",stdout);
    	return cin.tie(0),cout.tie(0),ios::sync_with_stdio(0),TC(),0;
    }
    /*
    1. CLEAR the arrays (ESPECIALLY multitests)
    2. DELETE useless output
     */
    
    • 1

    Information

    ID
    2938
    Time
    4000ms
    Memory
    512MiB
    Difficulty
    10
    Tags
    (None)
    # Submissions
    1
    Accepted
    1
    Uploaded By