Блог пользователя adyyy

Автор adyyy, история, 4 года назад, По-английски

Hi I tried to solve this problem based on bfs https://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://codeforces.com/contest/198/submission/85799856 . THANKS

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

»
4 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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

»
4 года назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится

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

  • »
    »
    4 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    okay but what difference does that make ??

    • »
      »
      »
      4 года назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      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 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    oh okay i got it thanks ..