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

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

Hi Codeforces community, can you help me to find the root of run time error in my solution for this problem 1428C - ABBB

Error is status_access_violation, google says it's something about pointers;

Submission link: 180179520

The approach is -> transform string to linked list of chars and when deleting two characters fix the "prev" for "next"; I generated "AB" strings up to 2^7, but it fails somewhere in 2^8, I'm not sure how to debug it; May be it's a memory leak issue?, I'm creating new pointers without deleting them, I tried using "delete pointer" but it did not help;

UPD

This was the solution https://codeforces.net/blog/entry/108880?#comment-971099

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

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

Not deleting pointers is not a good habit, but it won't cause runtime error in CP.

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

Did you really write 250 lines for a 1100 rated problem that is solvable with one for loop?

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

    Yeah, my bad, I implemented a working solution after not being able to debug pointers based, but could not let it go why it did not work;

    Turns out it's default value for pointers;

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

"I'm not sure how to debug it"

For example, you can just try. If you even tried in Custom Invocations, that you'd see that you've got fail in first testcase of test #2.
Another thing, you must know about C++ (and I hope that you knew that, but just forgot in that code) it is default initialization

class Node {
public:
  char val;
  int index;
  Node * prev;
  Node * next;
  Node(char c, int ind) {
    this->val = c;
    this->index = ind;
    // this->prev is garbage
    // this->next is garbage
  }
};
»
2 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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