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

Обсуждение задачи 1318. Логарифм

What the bug in the testing system?
solving this problem i've found the interesting bug in the testing system:

i submit the next code and get AC:

#include <cstdio>
#include <algorithm>
using namespace std;

[some code deleted :-]

int l[600000],r[600000],x[600000],y[600000];

[some code deleted :-]

int main()
{
    for (int i=0; i<900000; ++i)
        y[i]=rand();
// i add this two lines of code to my AC program

[some code deleted :-]

    return 0;
}

but i submit the next code and get Crash #1:

#include <cstdio>
#include <algorithm>
using namespace std;

int x[600000];
int y[600000];
int z[600000];

int main()
{
    for (int i=0; i<900000; ++i)
        y[i]=rand();
    printf("44");
    return 0;
}


why? can anybody help me?
Re: What the bug in the testing system?
Послано Lomir 4 янв 2008 06:25
There is no bug, except in your code.

Second code is UB (undefind behavour). C++ standard do not define variable "possitions" in heap.
As far as first one, I think it is also UB, however I am not sure about this.

One time C++ optimizator just puts all 3 arrays "near".
And second time, because of 3 different declatations, optimizator can make aligning to memory pages and put begining of each array into new page, this can make your program a little bit faster.
But going out out bounds gets access violation now.
Re: Re: What the bug in the testing system?
Thanks a lot, but can somebody explain me what must I do to get "access violation" in similar situations? Maybe exists some tricks like
#pragma comment(linker, "/stack:<new stack size>")
?