Блог пользователя Mong_Mang

Автор Mong_Mang, история, 10 месяцев назад, По-английски

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.

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

»
10 месяцев назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

which IDE do you use

  • »
    »
    10 месяцев назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    Codeblocks

    • »
      »
      »
      10 месяцев назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      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.

»
10 месяцев назад, # |
  Проголосовать: нравится +23 Проголосовать: не нравится

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

Also, compile with the -O2 flag.

  • »
    »
    10 месяцев назад, # ^ |
    Rev. 2   Проголосовать: нравится +11 Проголосовать: не нравится

    The complexity of my solution is O(n).

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

    • »
      »
      »
      10 месяцев назад, # ^ |
        Проголосовать: нравится +27 Проголосовать: не нравится

      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.

»
10 месяцев назад, # |
Rev. 2   Проголосовать: нравится +3 Проголосовать: не нравится

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.

»
10 месяцев назад, # |
  Проголосовать: нравится +9 Проголосовать: не нравится

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

»
10 месяцев назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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