Can anyone help me with this problem? COLORSEG — Coloring Segments
trying a long time didn't find any solution/hint.
Will be grateful if anyone can help. Thank You.
№ | Пользователь | Рейтинг |
---|---|---|
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 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
9 | nor | 153 |
Can anyone help me with this problem? COLORSEG — Coloring Segments
trying a long time didn't find any solution/hint.
Will be grateful if anyone can help. Thank You.
Название |
---|
The key is in your dp state to not just hold the color of your current segment, but of the current segment and previous segment.
How to solve this if we have only one condition (i < j < k)?
This question can be solved easily using dp with states 1. index , colour of last segment, colour of last to last segment. And for each state you will need to run a loop from 1 to m too .
So eventually adding this to test cases will lead to a O(T*N*M*M*M) solution ,but here we notice that the test cases aren't actually till 2500, since we know that the values of m ranges from 1 to 50.
So if we precompute for all m from 1 to 50, we solve the test case issue.
Here is my working code . Although I am not sure about the exact time complexity due to the coprime thing.
Got it ! Thanks
thank you anupamshah_.