-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path20413.cpp
70 lines (67 loc) · 1.69 KB
/
20413.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
61
62
63
64
65
66
67
68
69
70
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void solve(){
int N; cin >> N;
ll s,g,p,d; cin >> s >> g >> p >> d;
string str; cin >> str;
ll prev = 0;
ll result = 0;
for (int i = 0; i < N; i++) {
ll current = 0;
switch(str[i]) {
case 'B':
current = s-prev-1;
break;
case 'S':
current = g-prev-1;
break;
case 'G':
current = p-prev-1;
break;
case 'P':
current = d-prev-1;
break;
case 'D':
current = d;
break;
}
if (i + 1 < N) {
switch (str[i+1]) {
case 'B':
if (current > s-1)
current = max(current, s-1);
break;
case 'S':
if (current > g-1)
current = max(current, g-1);
break;
case 'G':
if (current > p-1)
current = max(current, p-1);
break;
case 'P':
if (current > d-1)
current = max(current, d-1);
break;
case 'D':
if (current > d)
current = max(current, d);
break;
}
}
if (current < 0) {
result += current;
current = 0;
}
result += current;
prev = current;
}
cout << result;
}
int main()
{
cin.tie(0)->sync_with_stdio(false);
solve();
return 0;
}