Zealotrahl's blog

By Zealotrahl, history, 2 years ago, In English

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://mirror.codeforces.com/blog/entry/108880?#comment-971099

  • Vote: I like it
  • +1
  • Vote: I do not like it

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

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

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

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

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

    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 years ago, # |
  Vote: I like it 0 Vote: I do not like it

"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 years ago, # |
  Vote: I like it 0 Vote: I do not like it

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