In Facebook Hacker Cup 2022 Round 2, I coded a right O(n) solution (C++) for Problem A, but I downloaded the input test case and ran the code. but it took me around 8 minutes to get the output. As a result, I couldn't submit the output. However, after the contest, I submitted the output and got accepted. Can anyone please tell me how can I compile fast or overcome this problem or any suggestions regarding this?
Note: I use Codeblocks IDE. Sometimes I use VS Code.
which IDE do you use
Codeblocks
In one of the Codeblocks toolbars, you can select
Debug
orRelease
. If you selectRelease
, the solution will be compiled with-O2
, which makes it much faster.What was the complexity of your solution? Are you sure it was meant to pass?
Also, compile with the
-O2
flag.The complexity of my solution is O(n).
Can you please give me some details about -O2 flag.
Instead of compiling like
g++ solution.cpp -o solution
, compile asg++ solution.cpp -O2 -o solution
.It enables certain optimizations, basically the compiler will be smarter and convert your code into a faster program.
Thank you. I'll try this and let you know.
You might want to check how fast you're reading the input. If a correct C++ solution took around 8 minutes, IO would be the culprit. If that's the case, you should use Fast IO.
If it's really a compilation what took so long (I doubt so) then just compile before downloading the input
my laptop cannot handle running large input and output. Is there any online judge which can compile very fast.
i personally suggest and prefer https://ide.usaco.guide
It didn't work for C question.