+ 2
Runtime error
https://code.sololearn.com/ci2XvU4m5s5y/?ref=app The program works fine for the input I have explained in the code but gives runtime error when I submit it.
19 Antworten
+ 4
My first optimization would be to see about eliminating the addition operation from cout<<res+1. That would reduce additions by t times. Can you initialize res=1 instead of res=0 and use cout<<res<<"\n"?
A note on coding style: Redefining standard types can reduce readability. I was tolerant before of using ll to mean long long int, but using ln was inconsistent and too easily confused with the mathematical function ln() - natural log. Any unnecessary deviation from familiar standards becomes a speed bump for others trying to read the code.
+ 2
HK Lite A little tweak in line 45 may give just enough boost to get it under 1 second. If you swap the conditional tests it might do fewer operations to determine a false condition.
Change from this:
if(((j+1)%y)!=0 && (arr[j]<x))
To this:
if(arr[j]<x && ((j+1)%y)!=0)
+ 2
Martin Taylor thanks it really helped :)
+ 1
Martin Taylor yes I know it works correctly for this input but gives runtime error on submission I don't know why.
Its a problem from a running contest and maybe its illegal but
https://www.codechef.com/AUG21C/problems/ARRFILL
Ill delete it if it is illegal.
Between when submitting there at codechef it gives runtime error.
If you have an account then pls try..
+ 1
Martin Taylor maybe 😶
and yes it is causing runtime error when submitting..
+ 1
Martin Taylor well... now I got TLE instead of 1sec its 1.010000sec 😬
+ 1
Martin Taylor sorry but I thought most of the people know about TLE and also long long was required for 10⁹ due to copy paste it resulted in 109 etc as constraints between thanks a lot for your time :)
+ 1
Martin Taylor ios_base is for fast input output in c++ as the constraints are big.
+ 1
Brian It helped with time limit but again Status : Runtime Error (OTHER) I guess I have to wait for contest to end :(
+ 1
With brians optimization runtime reduced to 0.500000sec Martin Taylor and after removing cin ios_base its 0.480000sec in both cases with runtime error :(
and it doesn't show where the problem is only says status: runtime error (OTHER).
+ 1
Brian is there any optimization that could be made in this program this is aslo resulting in 1.010000sec instead of 1sec
#include <iostream>
using namespace std;
#define ln long long int
int main() {
ln t;
cin>>t;
while(t--){
// ios_base::sync_with_stdio(false);
// cin.tie(NULL);cout.tie(NULL);
ln n,p,k;
cin>>n>>p>>k;
ln i=0,j=1;
ln res=0;
while(i!=p){
res++;
i+=k;
if(i>=n){
i=j;
j++;
}
}
cout<<res+1<<"\n";
}
return 0;
}
If you could help..
https://www.codechef.com/AUG21C/problems/CHFINVNT or Martin Taylor
0
A runtime error is a software or hardware problem that prevents Internet Explorer from working correctly. Runtime errors can be caused when a website uses HTML code that's incompatible with the web browser functionality. Original product version: Internet Explorer.
Greetings,
Peter