ENG  RUS Timus 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 1017. Staircases

JUDGE?
Posted by Artem Khizha [DNU] 28 Apr 2010 00:56
I wrote a primitive solution for this problem (there were more efficient ones discussed here, but I tried to solve task by myself first). But that's not a point. It crashed again and again with "Stack Overflow", though I can't understand why.

It is correct: I compiled it with GCC-G++, generated precalculations and get AC. But why "Stack Overflow"?

[C++]
#include <iostream>
#include <cstring>
using namespace std;

int main() {
int n;
double f[501][501];
memset(f, 0, sizeof(f));
cin >> n;
f[2][2] = 1;
for (int i = 3; i <= n; i++)    {
f[i][i] = 1;
for (int j = 1; j <= i; j++)
for (int k = j + 1; k < n; k++)
f[i][j] += f[i-j][k];
}
double sum = 0;
for (int i = 1; i < n; i++)
sum += f[n][i];
cout.precision(0);
cout.setf(ios_base::fixed);
cout << sum << endl;
return 0;
}
Re: JUDGE?
Posted by Sergey Lazarev (MSU Tashkent) 28 Apr 2010 01:26
Stack size is 1MB. Size of array "b" is about 2MB.
To avoid "Stack Overflow" you can:
1. declare "b" as global varialbe;
2. add directive (see also http://acm.timus.ru/help.aspx?topic=cpp)
#pragma comment(linker, "/STACK:16777216")
Re: JUDGE?
Posted by Artem Khizha [DNU] 29 Apr 2010 01:25
1Mb? Strange, that only now I expirienced this.
Thank you!