-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathM.cpp
60 lines (47 loc) · 852 Bytes
/
M.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
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;
const int N = 100010;
char s[N];
bool a[N], mark[N];
int main() {
int T, n, i;
scanf("%d", &T);
vector <int> vi;
char c;
while (T--) {
scanf("%d", &n);
scanf("%s", s);
a[0] = 0;
for (i = 1; i <= n; ++i) {
a[n - i + 1] = (s[i-1] == 'B') ? 0 : 1;
}
memset(mark, false, sizeof mark);
vi.clear();
int i = 1, left = 1;
while (i <= n) {
if (!mark[i] && a[i]) {
mark[i] = true;
a[i-1] ^= 1; a[i+1] ^= 1;
vi.push_back(n - i + 1);
if (a[i-1] && i > 1) {
i -= 1;
} else {
i = left;
}
continue;
} else {
left = max(left, i);
}
i++;
}
if (vi.size() == n) {
printf("Y\n");
for (int x : vi) printf("%d ", x);
} else printf("N");
printf("\n");
}
return 0;
}