codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

1245B.md (2670B)


      1 Source: https://codeforces.com/problemset/problem/1245/B
      2 
      3 B. Restricted RPS
      4 
      5 time limit per test
      6 
      7 1 second
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 Let $n$ be a positive integer. Let $a, b, c$ be nonnegative integers such that $a + b + c = n$.
     22 
     23 Alice and Bob are gonna play rock-paper-scissors $n$ times. Alice knows the sequences of hands that Bob will play. However, Alice has to play rock $a$ times, paper $b$ times, and scissors $c$ times.
     24 
     25 Alice wins if she beats Bob in at least $\lceil \frac{n}{2} \rceil$ ($\frac{n}{2}$ rounded up to the nearest integer) hands, otherwise Alice loses.
     26 
     27 Note that in rock-paper-scissors:
     28 
     29 * rock beats scissors;
     30 * paper beats rock;
     31 * scissors beat paper.
     32 
     33 The task is, given the sequence of hands that Bob will play, and the numbers $a, b, c$, determine whether or not Alice can win. And if so, find any possible sequence of hands that Alice can use to win.
     34 
     35 If there are multiple answers, print any of them.
     36 
     37 Input
     38 
     39 The first line contains a single integer $t$ ($1 \le t \le 100$) — the number of test cases.
     40 
     41 Then, $t$ testcases follow, each consisting of three lines:
     42 
     43 * The first line contains a single integer $n$ ($1 \le n \le 100$).
     44 * The second line contains three integers, $a, b, c$ ($0 \le a, b, c \le n$). It is guaranteed that $a + b + c = n$.
     45 * The third line contains a string $s$ of length $n$. $s$ is made up of only 'R', 'P', and 'S'. The $i$-th character is 'R' if for his $i$-th Bob plays rock, 'P' if paper, and 'S' if scissors.
     46 
     47 Output
     48 
     49 For each testcase:
     50 
     51 * If Alice cannot win, print "NO" (without the quotes).
     52 * Otherwise, print "YES" (without the quotes). Also, print a string $t$ of length $n$ made up of only 'R', 'P', and 'S' — a sequence of hands that Alice can use to win. $t$ must contain exactly $a$ 'R's, $b$ 'P's, and $c$ 'S's.
     53 * If there are multiple answers, print any of them.
     54 
     55 The "YES" / "NO" part of the output is case-insensitive (i.e. "yEs", "no" or "YEs" are all valid answers). Note that 'R', 'P' and 'S' are case-sensitive.
     56 
     57 Example
     58 
     59 Input
     60 
     61 ```
     62 2
     63 3
     64 1 1 1
     65 RPS
     66 3
     67 3 0 0
     68 RPS
     69 ```
     70 
     71 Output
     72 
     73 ```
     74 YES
     75 PSR
     76 NO
     77 ```
     78 
     79 Note
     80 
     81 In the first testcase, in the first hand, Alice plays paper and Bob plays rock, so Alice beats Bob. In the second hand, Alice plays scissors and Bob plays paper, so Alice beats Bob. In the third hand, Alice plays rock and Bob plays scissors, so Alice beats Bob. Alice beat Bob 3 times, and $3 \ge \lceil \frac{3}{2} \rceil = 2$, so Alice wins.
     82 
     83 In the second testcase, the only sequence of hands that Alice can play is "RRR". Alice beats Bob only in the last hand, so Alice can't win. $1 \lt \lceil \frac{3}{2} \rceil = 2$.