ronak037's blog

By ronak037, history, 4 years ago, In English

Hello guys, I hope you are doing well in this quarantine period. I want to share some small things from which my some question got WA instead of Accepted which needs to be taken care of while coding and I note down those points and also want to share with you. Maybe you already know them and maybe, for someone these are helpful.

  1. When we use pow function then it may give the wrong answer when we are using it for big values so instead, always add some changes while using it like instead of using directly, add 0.5 to it given value and then typecast into it int or long long as per the requirement. Example avoid writing pow(2,20), instead write (long long)(pow(2,20)+0.5). This will surely give the correct result.

[Edit]: please avoid using pow function as discussed in comments. Instead, use the divide and conquer method:

long long power(long long a,long long b)
{
    if(b==0) return 1;
    long long p = power(a, b/2);
    if(b&1) return p*p*a;
    else return p*p;
}
  1. Don't use sqrt function in a loop for comparison like this for(int i = 0; i <= sqrt(n); i++){} but precalculate the value of sqrt(n) and store it in different variable then use it in for loop. This is because if you don't precalculate the value then it may give TLE because every time loop will execute then every time it calculates sqrt(n).

  2. When we use v.size() for vector so this gives runtime error once in my solution because maybe I subtract some bigger value from its returned value which I didn't able to know during the contest then someone told me that .size() return unsigned long long value due to which this happens so from onwards I always start to typecast it into long long also such that that type of error will not come again. This is that solution: link

  3. Always typecast first value into a long double then use it in log function because otherwise, it may give the wrong answer due to some precision error in big values. Use log like this log((log double)z).

[Edit]: Instead of typecase you can also directly use logl function which automatically typecast and help to find the desired output.

These are some things that I learned during this quarantine period and this seems very small mistakes but very difficult to debug.

Thanks to all and also welcome other tips and suggestions. And please correct me if I am wrong somewhere.

Full text and comments »

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

By ronak037, history, 4 years ago, In English

I observed from a long time that in every contest there are some guys who add special cases to their solution to hack them after the contest which I think is not a good spirit. Like here this is a solution link of today's contest where he add some cases to get runtime error on the question A which is not good. They just use these things to increase their points by hacking them so please sir MikeMirzayanov take some actions against the id's like that.

Thank you.

Full text and comments »

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

By ronak037, history, 5 years ago, In English

In today's contest during submission of my solution of B question then I got runtime error again and again and not able to understand the reason for it because I don't get any error in my VSCode IDE. I am putting a link of my solution and also commented that line which gives an error so, please tell me why it is giving runtime error? Thanks for your help.

Question link: https://codeforces.me/contest/1350/problem/B Solution link: https://codeforces.me/contest/1350/submission/79905645

Full text and comments »

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

By ronak037, history, 5 years ago, In English

Basically I want to know how many loops we can iterate in 1 sec because according to me this number is approx 10^6 but in ques A of given link: https://codeforces.me/contest/1341/problem/A, I submitted a solution with brute force by thinking that it takes a maximum of 10^6 loops so I will not tle in system cases but that doesn't happen my solution got tle later and I relook into that solution and also not getting the reason why this solution get tle as it takes a maximum of 10^6 loops. Solution link: https://codeforces.me/contest/1341/submission/77777541. So please anyone explain to me the reason for this. Thank you

Full text and comments »

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

By ronak037, history, 5 years ago, In English

Question link: https://codeforces.me/contest/1334/problem/C.

I will attach my code further, in that in 3rd test case my answer coming incorrect but when I compiling same testcase in my VSCode then I get the correct results and I don't know why it is happening so please anyone helps me to resolve this. Thank You

Code link: https://codeforces.me/contest/1334/submission/76727603

Full text and comments »

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