QUESTION- https://www.spoj.com/problems/ABCPATH/7
MY SOLUTION- https://ideone.com/NAyzEI12
My code is continuously showing TLE.
Plz help me in optimizing my code.
created
last reply
- 2
replies
- 496
views
- 2
users
- 1
like
- 2
links
QUESTION- https://www.spoj.com/problems/ABCPATH/7
MY SOLUTION- https://ideone.com/NAyzEI12
My code is continuously showing TLE.
Plz help me in optimizing my code.
Consider a test case like this:
AAAEZZZZZZZZZZZZZZZZZZZZZZ
ABCDEFGHIJKLMNOPQRSTUVWXYZ
AAAZZZZZZZZZZZZZZZZZZZZZZZ
When you find those As and the adjacent B, how many times are you going to search the same path from B to the final Z? How many times do you need to search that same path starting from B?
Memoisation is the answer.
(As an aside, the code would be less repetitive and error prone if you stored the offsets for each direction in a couple of arrays.)
Topic | Category | Replies | Views | Activity |
---|---|---|---|---|
Help me please! | ProblemSet Archive | 4 | 43 | 27d |
What am i Missing | ProblemSet Archive | 1 | 171 | Feb 22 |
Beangame | ProblemSet Archive | 2 | 136 | Apr 9 |
What is wrong in my code…. i’m continuously getting runtime error(SIGSEGV)COT - Count on a tree | ProblemSet Archive | 4 | 213 | Feb 20 |
Getting TLE in AKBAR - Akbar , The great. Why? | ProblemSet Archive | 3 | 207 | Mar 11 |