-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path1245B Restricted RPS.cpp
92 lines (91 loc) · 2.19 KB
/
1245B Restricted RPS.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*
author : MishkatIT
created : Sunday 2023-07-23-22.22.31
*/
#include<bits/stdc++.h>
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define debug(_) cout << #_ << " is " << _ << '\n';
using namespace std;
using ll = long long;
using ld = long double;
const ll mod = 1e9 + 7;
const ll N = 1e5 + 10;
const ll inf = 1e9;
const ll linf = 1e18;
string ans = "";
void func(int& ra, int& pa, int& sa)
{
if(ra) {
ans += 'R';
ra--;
} else if(pa) {
ans += 'P';
pa--;
} else {
ans += 'S';
sa--;
}
}
int main()
{
fio;
int t;
cin >> t;
while(t--) {
ans.clear();
int n;
cin >> n;
int ra, pa, sa;
cin >> ra >> pa >> sa;
string str;
cin >> str;
int rb, pb, sb;
rb = pb = sb = 0;
for (auto& i: str) {
rb += (i == 'R');
pb += (i == 'P');
sb += (i == 'S');
}
int mn;
mn = min(sb, ra);
sb -= mn, ra -= mn;
mn = min(rb, pa);
rb -= mn, pa -= mn;
mn = min(pb, sa);
pb -= mn, sa -= mn;
// debug(ra)debug(pa)debug(sa)
// debug(rb + pb + sb)
if (n - (rb + pb + sb) < (n + 1) / 2) {
cout << "NO" << '\n';
} else {
for (auto& i: str) {
if(i == 'R') {
// cout << "dfd" << '\n';
if(rb) {
func(ra, pa, sa);
rb--;
} else {
ans += 'P';
}
} else if(i == 'P') {
if(pb) {
func(ra, pa, sa);
pb--;
} else {
ans += 'S';
}
} else {
if(sb) {
func(ra, pa, sa);
sb--;
} else {
ans += 'R';
}
}
}
// debug(ra)debug(pa)debug(sa)
cout << "YES" << '\n' << ans << '\n';
}
}
return 0;
}