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 | 3985 |
2 | jiangly | 3814 |
3 | jqdai0815 | 3682 |
4 | Benq | 3529 |
5 | orzdevinwang | 3526 |
6 | ksun48 | 3517 |
7 | Radewoosh | 3410 |
8 | hos.lyric | 3399 |
9 | ecnerwala | 3392 |
9 | Um_nik | 3392 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 169 |
2 | maomao90 | 162 |
2 | Um_nik | 162 |
4 | atcoder_official | 161 |
5 | djm03178 | 158 |
6 | -is-this-fft- | 157 |
7 | adamant | 155 |
8 | awoo | 154 |
8 | Dominater069 | 154 |
10 | luogu_official | 150 |
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_.