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 | 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 | 165 |
2 | maomao90 | 164 |
3 | Um_nik | 163 |
4 | atcoder_official | 160 |
4 | adamant | 160 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
8 | Dominater069 | 154 |
8 | nor | 154 |
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