ENG  RUSTimus Online Judge
Online Judge
Задачи
Авторы
Соревнования
О системе
Часто задаваемые вопросы
Новости сайта
Форум
Ссылки
Архив задач
Отправить на проверку
Состояние проверки
Руководство
Регистрация
Исправить данные
Рейтинг авторов
Текущее соревнование
Расписание
Прошедшие соревнования
Правила
вернуться в форум

Обсуждение задачи 1017. Лестницы

JUDGE?
Послано Artem Khizha [DNU] 28 апр 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?
Послано Sergey Lazarev (MSU Tashkent) 28 апр 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?
Послано Artem Khizha [DNU] 29 апр 2010 01:25
1Mb? Strange, that only now I expirienced this.
Thank you!