+ 1
Pls help. This code is showing that time limit exceeds on a particular ide and in some ide it is showing the desired output.
#include<stdio.h> int main() { int T; scanf("%d", &T); for (; T>0; T--) { int d,i,sum=0,count=0; int l,r; scanf("%d\n", &d); scanf("%d %d", &l,&r); for (i=l; i<r;i++) { if (i%2!=0) { count++; if(count>d&&count<=d+3 || count>d+6&&count<=d+9) continue; sum = sum + i; } } printf("%d\n", sum); } return 0; }
12 Respostas
+ 6
You can make it faster by moving all variable definitions out of the for loop so the space is only allocated once. Move the d+# out of inner loop so it is only calculated once. Change sum increment to: sum += i; which can be faster.
+ 6
This is what I suggested.
https://code.sololearn.com/c277pnFx6PSX
+ 4
Dynamic would cost more time over stack.
+ 4
Put current code in playground and link it here so I can look and play with it.
+ 1
Can't find any error. Though not what's the desired output seems working fine.
What's the compiler where it's failing? Or what's the error?
+ 1
Thank you.
0
Its saying time limit exceeded on codechef. Actually I was doing a contest where time limit for each question was set to be 1 second but my code took 1.01 second and that's where it failed.
0
Think that's telling you to improve your code.
You can try to improve the code.
0
John wells sir actually it's still not working. Can we use dynamic memory allocation here to decrease the time of execution?
0
Ok
0
Can you post the task? To see what the code is supposed to do.