Problem Set 1: Implementation — CS 334 — Spring 2025

Правка en1, от wsaleem, 2025-01-19 16:00:11

580448A - Robin Helps

We have to count the number of $$$0$$$s in $$$a$$$ that Robin encounters while he has gold. Robin's gold starts at 0, decrements for every $$$0$$$ encountered, but doe snot become negative, and increases by $$$a_i$$$ whenever $$$a_i\ge k$$$.

Original problem: 2014A - Robin Helps, leads to official tutorial and all solutions including WS solution: 282393143

580448B - Card Game

There are always 4 different ways in which the game can proceed. These can be brute-forced.

Original problem: 1999B - Card Game, leads to official tutorial and all solutions including WS solution: 274876674

580448C - Challenging Valleys

We record $$$l$$$, the starting index of the last valley, and $$$r$$$, the ending index of the first valley. If there is only one valley, then $$$a_l=a_{l+1}=a_{l+2}=\ldots=a_r$$$.

Note that every $$$a$$$ has at least 1 valley, so we will always find one $$$l$$$ and one $$$r$$$.

Original problem: 1760D - Challenging Valleys, leads to official tutorial and all solutions including WS solution: 269613934

580448D - Email from Polycarp

We can look at consecutive runs of letters in $$$s$$$ and in $$$t$$$. For positive output, the number of runs in each must be the same, and for each run, the letters in $$$s$$$ and $$$t$$$ must match, the length of the run in $$$t$$$ must be no less than that in $$$s$$$.

Original problem: 1185B - Email from Polycarp, leads to official tutorial and all solutions including WS solution: 247606625

580448E - Permutation Transformation

We can approach this problem recursively. This is feasible because $$$n$$$ is small, $$$1\le n\le 100$$$, so the recursion limit will not be encountered.

We maintain a separate array, $$$b$$$, of size $$$n$$$. Given indexes $$$i, j$$$ and depth, $$$d$$$, we find the index, $$$k$$$, of the maximum element in $$$a[i:j]$$$ (python slice indexing), set $$$b[k]=d$$$, and recurse for the subarrays to the left and right of index $$$k$$$. Recursion stops when the subarray contains a single element. For the first call, $$$(i, j, d) = (0, n, 0)$$$.

Original problem: 1490D - Permutation Transformation, leads to official tutorial and all solutions including WS solution: 258828754

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en1 Английский wsaleem 2025-01-19 16:00:11 2150 Initial revision (published)