-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMoons.cpp
143 lines (121 loc) · 3.18 KB
/
Moons.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
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
// Moons.cpp
// Created by David del Val on 26/03/2021
//
//
//https://github.com/Ddelval/Competitive-programming/blob/master/template.cpp
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
template <typename T, typename Q>
inline ostream &operator<<(ostream &o, pair<T, Q> p);
// ====================================================== //
// =================== Container IO =================== //
// ====================================================== //
template <bool B, typename T = void>
using Enable_if = typename std::enable_if<B, T>::type;
struct subs_fail {};
template <typename T>
struct subs_succeeded : std::true_type {};
template <>
struct subs_succeeded<subs_fail> : std::false_type {};
template <typename T>
struct get_iter_res {
private:
template <typename X>
static auto check(X const &x) -> decltype(x.begin());
static subs_fail check(...);
public:
using type = decltype(check(std::declval<T>()));
};
template <typename T>
struct Has_iterator : subs_succeeded<typename get_iter_res<T>::type> {};
template <>
struct Has_iterator<string> : subs_fail {};
template <typename T>
Enable_if<Has_iterator<T>::value, ostream &> operator<<(ostream &o, T val) {
bool first = true;
for (auto it = val.begin(); it != val.end(); ++it) {
if (!first)
o << " ";
first = false;
o << *it;
}
return o;
}
template <typename T = ll>
inline vector<T> readVector(int size) {
vector<T> v;
v.reserve(size);
T a;
for (int i = 0; i < size; ++i) {
cin >> a;
v.push_back(a);
}
return v;
}
// ====================================================== //
// ================== Pairs operations ================== //
// ====================================================== //
inline pii operator+(pii a, pii b) {
return {a.fi + b.fi, a.se + b.se};
}
template <typename T, typename Q>
inline ostream &operator<<(ostream &o, pair<T, Q> p) {
o << "(" << p.fi << "," << p.se << ")";
return o;
}
//gcd(0, n) = n
inline long long _gcd(long long a, long long b) {
while (b)
b %= a ^= b ^= a ^= b;
return a;
}
ll inf = LLONG_MAX / 10;
int iinf = INT_MAX / 10;
#ifdef _LOCAL_
//Local constraints
#else
// Judge constraints
#endif
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
int z = 0;
cin >> t;
while (t--) {
z++;
int x, y;
string moons;
cin >> x >> y >> moons;
ll cost = 0;
string m2;
for (char c : moons) {
if (m2.empty() || c != m2.back()) {
if (c != '?') {
m2.pb(c);
}
}
}
for (int i = 1; i < m2.length(); ++i) {
if (m2[i] == 'C' && m2[i - 1] == 'J') {
cost += y;
} else {
cost += x;
}
}
cout << "Case #" << z << ": " << cost << "\n";
}
return 0;
}