forked from Nihhaar/Competitive_Programming
-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathCF1550B.cpp
More file actions
71 lines (69 loc) · 1.39 KB
/
CF1550B.cpp
File metadata and controls
71 lines (69 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include<bits/stdc++.h>
using namespace std;
#define ll int long long
#define mp make_pair
//#define for(i,n) for(int i=0;i<n;i++)
#define F first
#define S second
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define N 1000000007
#define pq priority queue
#define pb push_back
#define pf push_front
#define mt make_tuple
#define prec(a) fixed<<setprecision(9)<<a
#define endl "\n"
#define fast_set s.max_load_factor(0.25);s.reserve(500);
#define cy cout<<"YES"<<endl;
#define cn cout<<"NO"<<endl;
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
const long double PI = (long double)(3.1415926535897932384626433832795);
int main()
{
fast;
int test,i,j,k,n,a,b;
// input number of testcases
cin>>test;
while(test--)
{
string str;
cin>>n>>a>>b;
// input string
cin>>str;
int ans=0;
if(b<0)
{
// maintain count of zeros and ones
int zero=0,one=0;
int last=-1;
for(i=0;i<n;i++)
{
if(str[i]-'0'!=last)
{
// if current char in str is '0'
if(str[i]-'0'==0)
{
// increment zero count
zero++;
}
else
{
// increment one count
one++;
}
//ans++;
}
last=str[i]-'0';
}
// calculating answer
ans=n*a+(min(zero,one)+1)*b;
}
else
{
ans=n*a+n*b;
}
cout<<ans<<endl;
}
return 0;
}