__Apocalypse__'s blog

By __Apocalypse__, history, 5 years ago, In English

Hi, I am getting TLE in Problem R — Walk Link to the question. Link to code

Tags #dp
  • Vote: I like it
  • 0
  • Vote: I do not like it

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by __Apocalypse__ (previous revision, new revision, compare).

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Did you try to take input by scanf and printf?

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Try using fast i/o :-

ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

»
5 years ago, # |
  Vote: I like it +8 Vote: I do not like it

On every solve or pro function call you allocate lots of vectors and than copy them to another function calls, allocating new vectors again and again.

You should probably create vectors once in main function and then pass it into functions by references, like that void solve(vector<vector<int>>& mat, int p, vector<vector<int>>& result). Or even make them global