Codeforces celebrates 10 years! We are pleased to announce the crowdfunding-campaign. Congratulate us by the link https://codeforces.com/10years. ×

__Apocalypse__'s blog

By __Apocalypse__, history, 5 weeks 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 weeks 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 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Did you try to take input by scanf and printf?

»
5 weeks 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 weeks 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