yeeeet's blog

By yeeeet, history, 4 months ago, In English,

Hello, My code is When I put in the sample test case 2 2 2 3 5 2 2 It gives a runtime error How can I fix this?


4 months ago, # |
  Vote: I like it 0 Vote: I do not like it

vector<vector<int> > v;


4 months ago, # |
Rev. 5   Vote: I like it 0 Vote: I do not like it

I tried in your code and found that the issue is not only in v[i].push_back(-1), but also in v[x+dirx[i]][y+diry[i]] in more than one position in the function bfs, here you are visiting places that have not reserved before.

For the first one, you haven't had the vectors v[i] yet, so you need either to create another vector and push -1's back to it, then push this vector back to v in each iteration, or to do this: vector <vector <int> > v(N); where N is the size you want for v.

For the second one, you need to be sure what you want in your code, so it is up to the idea of your solution.