-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathC.cpp
60 lines (48 loc) · 1.03 KB
/
C.cpp
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
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll ara[300009];
int main()
{
ll n, x, y;
cin >> n >> x >> y;
for(ll i = 1; i <= n; i++) {
char ch;
scanf(" %c", &ch);
ara[i] = ch - '0';
}
ll lst = 1, cst = 0, zero = 0;
bool check = 1;
for(ll i = 1; i <= n; i++) {
bool state = 0;
//cout << ara[i] << endl;
if(ara[i] == 1 && check == 0) {
if(x < y) {
cst += x;
state = 1;
}
else {
cst += y;
check = 1;
}
}
if(ara[i] == 0)
check = 0;
if(ara[i] == 1) {
for(; i <= n; i++) {
if(ara[i] == 0) {
i--;
break;
}
}
if(i > n && state) {
cst = cst - x + y;
check = 1;
}
}
}
if(!check)
cst += y;
cout << cst << endl;
return 0;
}