tafsiruzzaman's blog

By tafsiruzzaman, history, 3 months ago, In English

Hello Codeforces!

I’ve been facing an ongoing issue with Cloudflare’s browser verification on Codeforces, especially during the last Div. 3 round. Below are the screenshots of what I encountered:

During the contest, I spent around 20 minutes trying to resolve this problem, but I couldn't fix it. I eventually switched to m3.codeforces.com to continue. This issue keeps happening frequently. A few days ago, I couldn't submit my code in the last minute of the contest because of this verification. I don't know if others face this issue, but I’m experiencing it regularly.

Has anyone else faced this problem? How can I avoid this issue? Any help would be greatly appreciated!

Full text and comments »

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

By tafsiruzzaman, history, 5 months ago, In English

In the last Div.4 round, Problem 1985F - Final Boss witnessed numerous hacks, particularly targeting binary search solutions due to unexpected overflow in extreme cases.

A common challenge is determining the appropriate high-value for binary search: choosing it too high (e.g., 1e18) risks overflow, while choosing it too low (e.g., 1e9) may lead to incorrect answers. Finding the perfect static high-value for all cases can be tricky.

Here are two common fixes:

  1. Use a Very High Value and Handle Overflow with __int128(This approach can be complex and inefficient).
  2. Select a Suitable "High-Value" through Trial and Error (Not an ideal solution).

A More Sustainable Solution

As we know, binary search operates on a monotonic sequence such as [0, 0, 0, ..., 0, 1, ..., 1, 1, 1, 1]. Our objective is to find the last 0 or the first 1 in this sequence. If we successfully set the lo to any 0 zero and hi to any 1, our binary search will work perfectly. Now instead of relying on a static high-value for all cases, we can dynamically determine the minimum high-value necessary. This method involves starting with a low value and increasing it logarithmically until we find a suitable high-value. This ensures that our binary search operates within a safe range. Here's how you can implement this:

long long lo = 0, hi = 1;
while(!check(hi)) hi *= 2; // Check returns either 0 or 1 based on hi.

At the end of the loop, hi will point to a potential minimum high-value. After that, you can write your regular code. You can check my solution to understand the technique better.

My Solution

Note: I learn this technique from fahimcp495. Forgive me for any mistake.

I hope this technique will be helpful for those who don't know about this technique. Happy coding!

Full text and comments »

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