lucassf / UVA-Solutions

Solutions in c++ or Java to most of the UVA problems I've solved.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Problem K in ACMICPC SOUTH AMERICA CONTEST 2015

MauriPastorini opened this issue · comments

Hi, I saw that you solved this problem using Segment tree. I solved using DP with memoization but It throws me Runtime Error. I found that this issue it is probably because of a stackoverflow in the recursions due to the memoization techinque. Do you know how could you know that this tecnhique could not fit with the problem? Or anticipate somehow this runtime error? Thank you

Hi.
You can create a simple recursion and verify in which depth it raises segment fault error. For example, the following code gives runtime error for n = 64855 (windows) and n = 261778 (linux):

int test(int n){
cout<<n<<' ';
test(n + 1);
}

int main(){
test(1);
}

To solve your problem you can try replacing your recursive solution for an iterative one.
Or maybe the site the solution will run compiles the file with increased stack size, so no need to worry about runtime errors :)