https://codeforces.com/gym/580226/problem/A
#include<bits/stdc++.h>
#define lc p<<1
#define rc p<<1|1
#define INF 2e9
using namespace std;
#define endl '\n'
using ll = long long;
using pii = pair<ll, ll>;
const double PI = acos(-1);
const int N=1e4+10;
void solve(){
ll n,a,b;cin>>n>>a>>b;
string s;cin>>s;
s=" "+s;
ll ans=0;
ans+=a*n;
if(b>=0){
ans+=b*n;
}
else{
ll cnt0=0,cnt1=0;
for(int i=1;i<=n;i++)
{
if(s[i]!=s[i-1]&&s[i]=='0')
cnt0++;
if(s[i]!=s[i-1]&&s[i]=='1')
cnt1++;
}
ans+=(min(cnt0,cnt1)+1)*b;
}
cout<<ans<<endl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr), cout.tie(nullptr);
int T = 1;
cin>>T;
while (T--) {
solve();
}
return 0;
}
标签:const,int,ll,cin,solve,ans,字符串
From: https://www.cnblogs.com/laileou/p/18666531