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 1318. Logarithm

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?
Posted by Lomir 4 Jan 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>")
?