Can someone explain the solution in better way. I have read the tutorial but don't feel like getting it completely. Thank you. 1353E - K-periodic Garland
# | User | Rating |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3823 |
3 | Benq | 3738 |
4 | Radewoosh | 3633 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3390 |
10 | gamegame | 3386 |
# | User | Contrib. |
---|---|---|
1 | cry | 166 |
2 | maomao90 | 163 |
2 | Um_nik | 163 |
4 | atcoder_official | 161 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
9 | nor | 153 |
9 | Dominater069 | 153 |
Can someone explain the solution in better way. I have read the tutorial but don't feel like getting it completely. Thank you. 1353E - K-periodic Garland
Name |
---|
I did it in a slightly different way.
let dp[i] be the minimum number of ways substring s[1:i] can be k-periodic with the ith bulb switched on. Now while evaluating dp[i] we can face 2 situations.
2 If (i-k)th bulb is on, then
at each i I also considered the case that it can be the last bulb which is on and updated the ans accordingly.
ans = min(ans, dp[i] + (number of ways to switch off all the bulbs from i + 1 to n))
Step 1: Count the number of ones in the given string . Let it be "Ones" Step 2: Split the whole array into k different arrays, such that element i of the original array is now part of (i%k)th array . Now , we have to choose the best of these k arrays . Solving each array We need to find the starting and ending position in this array such that, the difference of ones and zeros is maximum in this range i.e. we need to set minimum number of 0s to 1s. Now, all we need is, number of 0s in this range + number of 1s outside this range + number of 1s in rest of the arrays (it can be counted with the help of "Ones", which we stored in step one. Here is the Implementation