adipro1167's blog

By adipro1167, history, 5 years ago, In English

Hello Codeforces! In yesterday's contest Codeforces Round 651 (Div. 2), on submitting the solution to B problem 1370B - GCD Compression, I encountered a Runtime Error on Pretest 1, when I submitted with GNU G++ 14 as the programming language. On my Sublime Text 3, it was working fine. Then, I tried submitting with GNU G++ 17(64 bit), and it got accepted. Have a look at my code: 84470670. Please help me in finding which line arose the error in GNU G++ 14 programming language and what is the basic difference between the two versions. Also, which one should I use as my default language? Thanks in advance!

Full text and comments »

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

By adipro1167, history, 5 years ago, In English

Hello Codeforces! In the contest, Codeforces Round #648, in B problem- Trouble Sort, I thought of using the Custom Compare Function, though later I realized it wasn't required here. But a general problem that I have faced in Custom Compare Function is that I have never understood its working. Sometimes, I make my own Custom Functions and they work but how- I don't understand. I read about it on Sort()-CPP Reference and Sort(): GeeksForGeeks but I did not understand its working. I wrote the following code:

#define lpr pair<long long int,long long int>
#define S second
#define F first
#define ll long long int
bool comparefn(lpr a, lpr b)
{
    if(a.S!=b.S)
    return a.F<=b.F;
    return false;
}

This is my custom compare function and I used it as:

vector<lpr> a;
sort(a.begin(),a.end(),comparefn)

It passed the first test case successfully but failed in the second one. On debugging I found that it fails for the following case:

5 1 5
0 0 1

Output: No But for the case:

5 5 1
0 1 0

Output: Yes. It works correctly.

Please explain me a dry run of this test case with the custom compare function which I have made. It would be of great help. Thanks in Advance!

Full text and comments »

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