I'm getting MLE at test 33 here is the problem
and my submission
here i used LIS dp -> time O(N^2), space O(N^2) .... i don't know how to convert space to O(n) and also at the same time get a particular solution.
# | User | Rating |
---|---|---|
1 | tourist | 3993 |
2 | jiangly | 3743 |
3 | orzdevinwang | 3707 |
4 | Radewoosh | 3627 |
5 | jqdai0815 | 3620 |
6 | Benq | 3564 |
7 | Kevin114514 | 3443 |
8 | ksun48 | 3434 |
9 | Rewinding | 3397 |
10 | Um_nik | 3396 |
# | User | Contrib. |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 155 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
10 | nor | 152 |
I'm getting MLE at test 33 here is the problem
and my submission
here i used LIS dp -> time O(N^2), space O(N^2) .... i don't know how to convert space to O(n) and also at the same time get a particular solution.
Name |
---|
Auto comment: topic has been updated by Aniket54 (previous revision, new revision, compare).
i will not get a solution if i do this ...to get a solution we need whole dp table right we can't space optimize it to 1D array
we can do it in O(n) space
Finding the length of LIS can be done by DP where $$$dp[i]$$$ is the maximum LIS having $$$a[i]$$$ as its last element.
To print the LIS, you can maintain a parent array which stores for each index, the index of the previous element of its LIS.
This can be done in $$$O(N^2)$$$ time and $$$O(N)$$$ space.
Submission Link ->
254290850I stored the elements as a $$$[w,[h,i]]$$$ pair and sorted it in ascending order. $$$O(NlogN)$$$. By this, we know all the elements to which $$$a[i]$$$ can attach to increase LIS will never occur after $$$a[i]$$$ itself as $$$w[i]<=w[j]$$$. Then, the logic of LIS will simply work for this question.
thanku