-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathB_Strange_Machine.cpp
More file actions
45 lines (39 loc) · 890 Bytes
/
B_Strange_Machine.cpp
File metadata and controls
45 lines (39 loc) · 890 Bytes
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
#include <bits/stdc++.h>
using namespace std;
void solve(){
int n,q;cin>>n>>q;
string s;cin>>s;
int a=0,b=0;
for (int i = 0; i < n; i++)
{
if(s[i]=='A') a++;
if(s[i]=='B') b++;
}
while(q--){
int x;cin>>x;
if(b==0){
cout<<x<<endl;
// continue;
}else{
int ans=0;
while(x>0){
for (int i = 0; i < n; i++)
{
if(x==0) break;
if(s[i]=='A') x--;
else x/=2;
ans++;
}
}
cout<<ans<<endl;
}
}
}
int main()
{
int t;cin>>t;
while(t--){
solve();
}
return 0;
}