-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIron_Magnet_and_Wall.cpp
More file actions
56 lines (53 loc) · 1.46 KB
/
Iron_Magnet_and_Wall.cpp
File metadata and controls
56 lines (53 loc) · 1.46 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
49
50
51
52
53
54
55
56
#include <bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false),cin.tie(NULL), cout.tie(NULL)
#define REP(i, start, end) for(auto i = start; i < end; i++)
//#define FORJ(start, end) for(auto j = start; j < end; j++)
int main(){
FASTIO;
int t;
cin >> t;
while(t--){
int n, k;
string fem;
cin >> n >> k;
cin >> fem;
int i=0,j=0,ans=0,c=0, P;
REP(l, 0, n) {
if(fem[l] == 'M') {
i = l;
break;
}
}
REP(l, 0, n) {
if(fem[l] == 'I') {
j = l;
break;
}
}
while(i < n && j < n){
if(fem[i] == 'M'){
if(fem[j] == 'I'){
REP(l, i+1, j){
if(fem[l] == ':') c++;
}
P = k + 1 - abs(i-j) - c;
if(P > 0){
ans++;
i++; j++; c=0;
} else if (P < 0) {
if(i > j) j++;
else if (j > i) i++;
}
} else if (fem[j] == 'X'){
j++; i = j;
} else j++;
} else if (fem[i] == 'X') {
i++; j = i;
}
else i++;
}
cout << ans << endl;
}
return 0;
}