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
- 492
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 |
---|---|---|---|---|
Getting WA on the problem PIE continuously, what am I missing? spoj.com | ProblemSet Archive | 2 | 172 | Mar 8 |
ADV04F - Four Chips(hard) HELP! | ProblemSet Archive | 1 | 49 | 14d |
Help me please! | ProblemSet Archive | 4 | 18 | 5d |
AIBOHPHOBIA - LPS vs Direct Approach | ProblemSet Archive | 1 | 110 | Mar 31 |
ABCPATH - ABC Path | ProblemSet Archive | 1 | 88 | May 11 |