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

Why Crash?
Posted by Tirex 29 Jun 2009 01:44
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main()
{
    const unsigned int N=32768;
    unsigned long long xl[N];
    unsigned int col=0;
    cin.setf(ios::skipws);
    while(cin>>xl[col]) col++;
    cout.unsetf(cout.flags());
    cout.setf(ios::showpoint|ios::fixed|ios::dec);
    while(col--) cout<<setprecision(4)<<sqrt((double)xl[col])<<endl;
    return 0;
}
Re: Why Crash?
Posted by Tirex 29 Jun 2009 04:19
Decided. Please explain some of the time, please.

#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
typedef unsigned long long Beta;
int main()
{
    const unsigned int N=128*1024;
    Beta *xl=new Beta[N];
    int col=0;
    cin.setf(ios::skipws);
    while(cin>>xl[col]) col++;
    cout.unsetf(cout.flags());
    cout.setf(ios::showpoint|ios::fixed|ios::dec);
    while(col--) cout<<setprecision(4)<<sqrt((double)xl[col])<<endl;
    delete []xl;
    return 0;
}

The size of the input stream 256 kb.
So we need to allocate memory in the amount of (256*1024)/sizeof(_int64);
Why is the correct decision should be 128 * 1024?