-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path681B.cpp
More file actions
110 lines (104 loc) · 2.52 KB
/
Copy path681B.cpp
File metadata and controls
110 lines (104 loc) · 2.52 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include <bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin >> t;
while (t--)
{
int a, b;
cin >> a >> b;
string s;
string s1;
cin >> s;
s1 = s;
int cnt = 0;
for (int i = 0; i < s1.size()-1; i++)
{
// if(s[i]=='0' && s[i+1]=='0'){
// s1[i]='L';
// }
if(s[i]=='1' &&s[i+1]=='1'){
s1[i]='L';
}
}
int zero = 0;
for (int i = 0; i < s.size(); i++)
{
if(s[i]=='0'){
zero++;
}
}
string s2;
for (int i = 0; i < s1.size(); i++)
{
if(s1[i]=='L'){
continue;
}
else
{
s2.push_back(s1[i]);
}
}
int one = 0,zero1 = 0;
int one1 = 0;
for (int i = 0; i < s2.size(); i++)
{
if(s2[i]=='1'){
one++;
}
}
int ans = 0;
// cout << s2 << endl;
// printf("%d\n",s2.size());
for (int i = 0; i < s2.size();)
{
if(s2[i]=='1'){
one1 = i;
i++;
bool over = false;
if(i == s2.size()){
over= true;
}
while (s2[i]!='1' &&i <s2.size())
{
i++;
if(i==s2.size()){
over = true;
break;
}
}
if(over){
ans += a;
break;
}
if(ans == 0){
if((i-one1-1)*b <=a){
ans += ((i-one1-1)*b);
// printf("1%d\n",ans);
}
else
{
ans += a;
// printf("2%d\n",ans);
}
}
else if((i-one1-1)*b <=a){
ans += ((i-one1-1)*b);
// p/rintf("3%d\n",ans);
}
else
{
ans += a;
// printf("%d\n",ans);
}
one1 = i;
}
else
{
i++;
}
}
cout << ans <<endl;
}
}