ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1001. Reverse Root

getting a runtime error (stackoverflow)
Posted by Ajinkya 24 Jun 2015 16:15
#include<iostream>
#include<math.h>

int main()
{
 using namespace std;
 int i;
 float r,a[128*64];
 unsigned long long n,j,k;
 for(i=0;i<n;i++)
  cin>>a[i];
 j=n-1;
 for(k=j;k>=0;k--)
 {
  r=sqrt(a[k]);
  cout<<r<<"\n";
 }
 return 0;
}
Re: getting a runtime error (stackoverflow)
Posted by Surya Prakash Tiwary 15 Dec 2015 16:31
You should try to increase the size of your array and perhaps use a double array over float.
Slowpokes to the rescue - Re: getting a runtime error (stackoverflow)
Posted by ToadMonster 15 Dec 2015 20:46
> A size of the input stream does not exceed 256 KB

Minimum number of chars per number is 2 - "0 ". So you have to receive up to 128 K numbers. Your array is about 8 K numbers.

You shouldn't allocate such big arrays on stack. Use dynamic allocation or std::vector.

And another note.
> unsigned long long n,j,k;
> for(i=0;i<n;i++)
>  cin>>a[i];

How many times will this for iterate? Why?

Edited by author 15.12.2015 21:02
Re: getting a runtime error (stackoverflow)
Posted by Majin Boo 10 Jan 2016 22:48
It's preferable to use a double precision floating point type over a single float. n is not given in the input data. I recommend to use std::vector to alloc it:

vector <double> input;
double aux;
while(cin>>aux) input.push_back(aux);