+ 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.

10th Aug 2021, 7:51 PM
HK Lite
HK Lite - avatar
19 odpowiedzi
+ 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.
11th Aug 2021, 7:00 PM
Brian
Brian - avatar
+ 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)
11th Aug 2021, 1:34 AM
Brian
Brian - avatar
+ 2
Martin Taylor thanks it really helped :)
11th Aug 2021, 4:06 AM
HK Lite
HK Lite - avatar
+ 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..
10th Aug 2021, 11:27 PM
HK Lite
HK Lite - avatar
+ 1
Martin Taylor maybe 😶 and yes it is causing runtime error when submitting..
11th Aug 2021, 12:32 AM
HK Lite
HK Lite - avatar
+ 1
Martin Taylor well... now I got TLE instead of 1sec its 1.010000sec 😬
11th Aug 2021, 12:57 AM
HK Lite
HK Lite - avatar
+ 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 :)
11th Aug 2021, 1:57 AM
HK Lite
HK Lite - avatar
+ 1
Martin Taylor ios_base is for fast input output in c++ as the constraints are big.
11th Aug 2021, 1:59 AM
HK Lite
HK Lite - avatar
+ 1
Brian It helped with time limit but again Status : Runtime Error (OTHER) I guess I have to wait for contest to end :(
11th Aug 2021, 2:09 AM
HK Lite
HK Lite - avatar
+ 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).
11th Aug 2021, 1:40 PM
HK Lite
HK Lite - avatar
+ 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
11th Aug 2021, 1:49 PM
HK Lite
HK Lite - avatar
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
18th Oct 2022, 6:03 AM
Peter