My submission(Problem D). returns the correct answer on all test cases but gets TLE on higher recursion levels. I am unable to understand how memoization can be implemented in this case. Any help would be appreciated.
My submission(Problem D). returns the correct answer on all test cases but gets TLE on higher recursion levels. I am unable to understand how memoization can be implemented in this case. Any help would be appreciated.
| # | User | Rating |
|---|---|---|
| 1 | Benq | 3676 |
| 2 | Kevin114514 | 3659 |
| 3 | jiangly | 3640 |
| 4 | turmax | 3450 |
| 5 | tourist | 3382 |
| 6 | strapple | 3360 |
| 7 | Um_nik | 3354 |
| 8 | squareOf105 | 3348 |
| 9 | maroonrk | 3312 |
| 10 | idontwannadothis…e | 3191 |
| # | User | Contrib. |
|---|---|---|
| 1 | Qingyu | 156 |
| 2 | nik_exists | 151 |
| 3 | maspy | 149 |
| 4 | AmShZ | 145 |
| 5 | Um_nik | 143 |
| 6 | Errichto | 139 |
| 7 | BledDest | 136 |
| 8 | adamant | 135 |
| 9 | maroonrk | 132 |
| 10 | cry | 130 |
| Name |
|---|



There can be at-most
2^29particles afterNexplosions. If you consider a state of the particle in terms of Grid,Level,Direction(X,Y,T,Dir)fromPigeon Hole Principlethere must exist (at some point2^k > 321^2 * 30 * 3^2) two or more particles starting in the same Grid, moving in the same direction at the Same level. For these kinds of particles,you only need to track one instance (Memoize instances)of it. By this way you wont be keeping track of more than321^2 * 8particles at an instance.This leaves you with a complexity of
O(Height*Breadth*Levels*Distance*Directions)O(N^2 * 30 * 5 * 8)O(N^2)