Пожалуйста, прочтите новое правило об ограничении использования AI-инструментов. ×

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

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

Here are two solutions to problem D of today's contest

1.First solution

My Code
  1. Second solution
His Code

The first one shows TLE on testcase 8 while the second one shows accepted. Both are same solutions to the problem.

Does anyone know why the results are so different?

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

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

Auto comment: topic has been updated by FullMetalChains (previous revision, new revision, compare).

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

Fast IO

Add this line to the beginning of your code and it will pass the tests:

cin.tie(0) -> sync_with_stdio(0);
Explanation:
  • »
    »
    13 месяцев назад, # ^ |
      Проголосовать: нравится +8 Проголосовать: не нравится

    This is so unfortunate. I resubmitted the answer I had during the contest(It gave TLE at that time) and now, it passed now. I feel robbed :(

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

    I also noticed that FullMetalChains uses endl in submissions. For a similar reason, you should try using '\n' instead for non-interactive problems so it avoids flushing.

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

      I always add #define endl '\n', I find it easier to just comment it out on interactive problems. (If you are used to writing endl like me, you might consider doing this as well)

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

Auto comment: topic has been updated by FullMetalChains (previous revision, new revision, compare).