Facebook hacker cup question D1

i know declaring an array of size up to 10^8 globally is possible ,but using array of size greater than 10^5 is not possible in local computer(specially for my case 8gb of ram)

why not?

i tried many online ide but i can’t paste array of size >10^4

okay now it’s working,i got my mistake and i learned something new ,thanks to all of you guys :smile:

hey can you tell what you were doing wrong… I ha faced similar issues while solving codechef problems. I cant make array size greater that 10^5 in local computer but same code works in codechef ide. Maybe your solution can help me if your problem is something similar.(I use codeblocks).

just declare the array globally

any hint for this question??

Nope .

1 Like

this is not long challenge :man_shrugging:

Can we download/see other contestants solutions after contest?

Yeah

tried that but it works only till array size of 810^5
And while i make a new array for every single test case it works till 5
10^5

what is error,i mean code is not exiting or you are getting any runtime error?

You can write this command in prompt to compile and then run the executable a.exe -
g++ -O2 -std=c++11 -Wall -Wl,--stack=268435456 a.cpp -o a.exe

Even my laptop has ram of 8gb, it’s possible for me. So, it should be for you too!

What was the mistake?

i was redeclaring the array inside main() too.

use online compiler , i use “compile c++ gcc online” , if the array is so large.

//g++  7.4.0

#include <iostream>

int main()
{
    int n=100000;
    while(n--){
        int a[100000000]={0};
    }
}

I used a single vector of size 1e6 + 5. It was ok with my system. and also on Online platforms, make sure you not running out of stack due to other reason.

finished but printing nothing
,this is working fine