strange matrix

how to allocate array of 10^5 in C
int matrix[100000][100000];
shows error : size of array matrix is too large

You are trying to allocate 10^10 elements, each of 4 bytes, i.e. 4*(10^10) bytes, which is around 37.25 GB of memory. Your RAM may not be having enough memory to store the array.


but even codechef is giving this error

prog.c: In function �main�:
prog.c:4:7: error: size of array �mat� is too large
int mat[100000][100000];
prog.c:4:7: warning: unused variable �mat� [-Wunused-variable]

still not working … please help!

@amita0809 It will never work on any online judge or normal home PCs. How can you allocate 37 GBs of memory when you don’t even have that much? The memory limit at Codechef is 1536 MBs.

1 Like

@gautam94 so what shall i do then ? can u suggest some alternate way

Try to think something different dont stick to one logic think how can i handle the same logic which you have build up with using less memory space and so on…you will definitely end up with some trick…


Nice comment @tech_boy. This is why I love Codechef.

hi guys i have successfully satisfied the given test case and also my own generated test cases and i got the correct answers all the time.but when i submit the judge says wrong answer.
i don’t understand what happens in the n=m=1 case.
please help me out.

@tech_boy … thankz !! i worked my way out :slight_smile:

I have the same problem…getting WA:) Found that I have bugs :frowning:

Read the problem statement carefully every single word has meaning and it will make you understand all test cases and language use is clear and simple too