Mong_Mang's blog

By Mong_Mang, history, 14 months ago, In English

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.

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

»
14 months ago, # |
  Vote: I like it 0 Vote: I do not like it

which IDE do you use

  • »
    »
    14 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Codeblocks

    • »
      »
      »
      14 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      In one of the Codeblocks toolbars, you can select Debug or Release. If you select Release, the solution will be compiled with -O2, which makes it much faster.

»
14 months ago, # |
  Vote: I like it +23 Vote: I do not like it

What was the complexity of your solution? Are you sure it was meant to pass?

Also, compile with the -O2 flag.

  • »
    »
    14 months ago, # ^ |
    Rev. 2   Vote: I like it +11 Vote: I do not like it

    The complexity of my solution is O(n).

    Can you please give me some details about -O2 flag.

    • »
      »
      »
      14 months ago, # ^ |
        Vote: I like it +27 Vote: I do not like it

      Instead of compiling like g++ solution.cpp -o solution, compile as g++ solution.cpp -O2 -o solution.

      It enables certain optimizations, basically the compiler will be smarter and convert your code into a faster program.

      • »
        »
        »
        »
        14 months ago, # ^ |
          Vote: I like it +2 Vote: I do not like it

        Thank you. I'll try this and let you know.

»
14 months ago, # |
Rev. 2   Vote: I like it +3 Vote: I do not like it

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.

»
14 months ago, # |
  Vote: I like it +9 Vote: I do not like it

how can I compile fast

If it's really a compilation what took so long (I doubt so) then just compile before downloading the input

»
14 months ago, # |
  Vote: I like it 0 Vote: I do not like it

my laptop cannot handle running large input and output. Is there any online judge which can compile very fast.