I keep encountering a runtime error on test case 4 in my solution. I would greatly appreciate it if someone could help me identify the reason.
Problem Link: 1931E — Codeforces My Submission: 300919011
It might be a simple issue, but I’ve spent hours figuring it out without success.
Auto comment: topic has been updated by XoXoHarsh (previous revision, new revision, compare).
Just dont create unnecessary strings, and use long long everywhere.
Thank you for providing the corrected code. However, I am still confused about why using long long or a string everywhere would result in a runtime error.
Is it related to the internal workings of the sort function? I don’t think I have used string or long long in a way that would cause an MLE (Memory Limit Exceeded) or runtime error.
yes, I try to avoid to_string() just because it can cause memory to get filled very fast. Also internally when you are sorting, >= sign can change the relative postions of the elements. rather use stable_sort() if you want to use >=.
Thanks
When using a comparison function in sorting, it is incorrect to use: cnt1 <= cnt2
The correct approach is: cnt1 < cnt2
This ensures that the sorting algorithm properly defines a strict ordering.
Your code you can check line 138
If you return true when the arguments are equal, it implies that you want the first element to precede the second, while simultaneously wanting the second element to precede the first. This creates a contradiction.
Oh, I didn’t know about that. Thanks! Just removing the ‘=’ made the code work. But why is strict ordering necessary?
I mean, doesn’t the comparison function only need to return true or false? Why does strict ordering matter?
i updated my comment check this
Thank you very much; I understood it.
Auto comment: topic has been updated by XoXoHarsh (previous revision, new revision, compare).