Runtime error in a atcoder problem.

Правка en1, от I_lOVE_ROMAN, 2022-03-09 12:42:15

Here is the link of problem at atcoder:

I tried it with a naive recursion approach. It's running good with the testcases in my pc but getting RE in atcoder compiler. I have no clue how it is getting RE.

Here is the solution


#include<bits/stdc++.h> using namespace std; int N,sum=0,mn=INT_MAX,h[100006]; int recur(int i,int sum) { if(N>=4) { return mn=min(sum,mn); } else { recur(i+1,sum+abs(h[i+1]-h[i])); recur(i+2,sum+abs(h[i+2]-h[i])); } } int main() { int n,i,j,k; cin>>N; for(i=1;i<=N;i++) { cin>>h[i]; } cout<<recur(1,0)<<endl; return 0; }

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en1 Английский I_lOVE_ROMAN 2022-03-09 12:42:15 761 Initial revision (published)