Hi^^,
Can someone explain me the problem of SEERC2020 — Problem I? [I didn't understand the editorial]
And share the code if possible.
Link of problem : PROBLEM I
| № | Пользователь | Рейтинг |
|---|---|---|
| 1 | Benq | 3792 |
| 2 | VivaciousAubergine | 3647 |
| 3 | Kevin114514 | 3603 |
| 4 | jiangly | 3583 |
| 5 | strapple | 3515 |
| 6 | tourist | 3470 |
| 7 | dXqwq | 3436 |
| 8 | Radewoosh | 3415 |
| 9 | Otomachi_Una | 3413 |
| 10 | Um_nik | 3376 |
| Страны | Города | Организации | Всё → |
| № | Пользователь | Вклад |
|---|---|---|
| 1 | Qingyu | 158 |
| 2 | adamant | 152 |
| 3 | Proof_by_QED | 146 |
| 3 | Um_nik | 146 |
| 5 | Dominater069 | 144 |
| 6 | errorgorn | 141 |
| 7 | cry | 139 |
| 8 | YuukiS | 135 |
| 9 | chromate00 | 134 |
| 9 | TheScrasse | 134 |
| Название |
|---|



This was a really nice problem I remember solving at the SEERC. But it would be helpful if you mentioned which part is unclear to you.
In general this is the solution:
notice that you can't have $$$p_i \lt p_{i+1}$$$ except when $$$p_i \leq 2$$$. This means that we will have a pseudo-decreasing array, which actually consists of 1, 2, decreasing array between 1-2, decreasing array between 2-1
if we can find the ways to separate the elements into two decreasing arrays like this, we can easily calculate the solution
notice that elements $$$a$$$ and $$$a-1$$$ can always go after another, so we can place entire segments of consecutive elements into one segment
therefore, we can have $$$dp_i$$$ which is the number of ways to construct these arrays, such that one ends on $$$i$$$ and another ends on $$$i+1$$$
we can "select" the previous element $$$x$$$ which is the array which ends with $$$i$$$
as these two arrays are symmetrical, this adds $$$dp[x-1]$$$ to $$$dp[i]$$$
there are about $$$3\cdot \frac{n}{i}$$$ of this options which sums into $$$O(NlogN)$$$ (google harmonic sum if you don't know this)
I don't have code as I participated onsite
thanks ^^ , i got it