-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathall_the_gates.cpp
More file actions
executable file
·48 lines (43 loc) · 1.25 KB
/
all_the_gates.cpp
File metadata and controls
executable file
·48 lines (43 loc) · 1.25 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
// g++ all_the_gates.cpp -o all_the_gates && ./all_the_gates
/*
*/
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cerr.tie(NULL)
#define endl '\n'
#define int long long int
using namespace std;
#define pii pair <int, int>
#define pb push_back
#define deb(x) cout << #x << " " << x << endl
#define deb2(x, y) cout << #x << " " << x << " " << #y << " " << y << endl
#define loop(s, e, itr) for (int itr = s; itr < e; itr++)
#define vin vector<int>
#define w(t) int tc; cin >> tc; for(int t = 1; t <= tc; t++)
int32_t main(){
fastio;
int k, n;
w(t){
cin >> n >> k;
vector<char> arr(n);
loop(0, n, i) cin >> arr[i];
bool flag= false;
for(int i = 1; i <= k; i++){
if(flag){
if(arr[n-i] == 'T') flag = false;
}
else if(arr[n-i] == 'H') flag = true;
}
int ans = 0;
if(flag){
for(int i = k+1; i <= n; i++) {
if(arr[n-i] == 'T') ans++;
}
}
else {
for(int i = k+1; i <= n; i++) {
if(arr[n-i] == 'H') ans++;
}
}
cout << ans << endl;
}
}