-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2156b.cpp
More file actions
49 lines (41 loc) · 951 Bytes
/
2156b.cpp
File metadata and controls
49 lines (41 loc) · 951 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
46
47
48
49
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
int n,q;
cin >> n >> q;
string s;
cin >>s;
vector<long long> a(q);
for(int i = 0;i < q;i++) cin >> a[i];
bool hasB = false;
for(char c : s)if(c =='B') {
hasB = true;
break;
}
if(!hasB){
for(int i =0;i<q;i++){
cout << a[i] << "\n";
}
continue;
}
for(int i = 0;i<q;i++){
long long x = a[i];
long long secs = 0;
int idx = 0;
while(x > 0){
if(s[idx] == 'A')x=x-1;
else x=x/2;
secs++;
idx++;
if(idx == n)idx=0;
}
cout << secs << "\n";
}
}
return 0;
}