-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path1559B.cpp
78 lines (71 loc) · 1.71 KB
/
1559B.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <bits/stdc++.h>
#define FOR(i, start, end) for(int i = start; i < end; i++)
#define ROF(i, start, end) for(int i = end; i > start; i--)
#define FORO(i, end) for(int i = 0; i < end; i++)
#define ROFO(i, start) for(int i = start; i >= 0; i--)
#define pub push_back
#define fir first
#define sec second
#define pob pop_back
#define mp make_pair
#define read_arr(arr, start, end) for (int i = start; i < end; i++) { cin >> arr[i]; }
#define vi vector<int>
#define vl vector<long>
#define pii pair<int, int>
using namespace std;
typedef long long LL;
typedef long double LD;
char flipper(char x, int amo) {
bool flip = amo & 1;
if (flip) {
return (x == 'R') ? 'B' : 'R';
}
else {
return (x == 'R') ? 'R' : 'B';
}
}
void solve() {
int n, lastCharPos;
cin >> n;
string s;
char lastChar = ' ';
cin >> s;
FORO(i, n) {
if (s[i] != '?') {
// flood fill sebelah kiri
lastCharPos = i;
lastChar = s[i];
bool red = (s[i] == 'R');
int tmp = i - 1;
while (tmp >= 0 && s[tmp] == '?') {
red = !red;
s[tmp] = (red) ? 'R' : 'B';
tmp--;
}
}
}
ROFO(i, n-1) {
if (s[i] == '?') {
// flood fill sebelah kiri
bool red = flipper(lastChar, i-lastCharPos+1) == 'R';
int tmp = i;
while (tmp >= 0 && s[tmp] == '?') {
red = !red;
s[tmp] = (red) ? 'R' : 'B';
tmp--;
}
}
}
cout << s << '\n';
}
int main() {
int t;
cin >> t;
while (t--) solve();
}
// counter case
// 1
// 4
// BB??
// BBBR
// should be BBRB