adyyy's blog

By adyyy, history, 4 years ago, In English

Hi I tried to solve this problem based on bfs https://mirror.codeforces.com/problemset/problem/198/B . Also I have implemented it well and it passes for 28 test cases butgives MEMORY LIMIT EXCEE. on test 29 . May be there is something to learn here . please anybody hep if you can figure out whats wrong . Here is my submission https://mirror.codeforces.com/contest/198/submission/85799856 . THANKS

  • Vote: I like it
  • 0
  • Vote: I do not like it

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

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

»
4 years ago, # |
  Vote: I like it +1 Vote: I do not like it

Consider marking the state visited while pushing them in the queue. 85803410

  • »
    »
    4 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    okay but what difference does that make ??

    • »
      »
      »
      4 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      It is possible that many states lead to the same sub-state. In that case you get multiple instances of same sub-state in the queue. Notice that the sub-state is marked visited only when it is processed. But before it is processed there can be copies of it in the queue which unnecessarily increases the queue size, giving you MLE.

  • »
    »
    4 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    oh okay i got it thanks ..