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

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

problem statement: https://codeforces.me/problemset/problem/1977/B

my submission: https://codeforces.me/contest/1977/submission/315209972

there is no nesting in any loop, and any loop runs atmost 32 times, why is my code exceeding time limit of 1 second??

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

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

why is there an n++ inside of your loop.

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

My (unverified) guess is that you're bottlenecked by the I/O operations. I checked all the accepted submissions written in C for this problem and they're all manually constructing the output string and then printing it all at once. Try printing out the array all at once and see if that gets AC.

I came across https://codeforces.me/blog/entry/68043?#comment-523265 which mentions that C11 is slow on CF and the reply to that comment seems to be having a similar issue.

Also, a general coding style tip: try to initialize your variables' values when you declare them. I spent a bit of time trying to figure out if any of your variables were uninitialized. You're by no means required to take this advice, but I find it helps with readability when you (or someone else) needs to debug your code.