Unordered map-AC While Map-TLE in CLBRKT

But i have declared my array in main which can access maximum index as [(10^6)-1], but in this question input is 10^7 ,So How array is accessing [(10^7)-1]th index?

1 Like

Yes, But in the Problem it’s written that
" Sum of |S|and Q over all testcases for a particular test file does not exceed 10^7 and 10^6 respectively."

But we should not take it for granted that there will be no such string with length as 10^7.May be they have included only one test file and its written to trick the participant. Right?

Yep. As @sebastian says, I don’t think they had any 10^7 size string. :face_with_hand_over_mouth:

1 Like

They had…I used assert statements to check.

1 Like

I just tried in cc IDE to create an array of size 1e7 in main and it ran

2 Likes

I think you should write following statement:

assert (n==1e7);

instead of:

assert (n<=5*1e6);

Because we are checking if there is a input of 10^7 or not.
Am i Right?

No…try to understand on your own.

1 Like

Can You Explain Please… Not able to undertand!

Bro Can You Explain Why is the Following Running. It Blew My Mind:
Click Here

Okay, there will be many cases… in some cases n will be 1e6(say) and 1e7 in others. So former assert statement will always give re because Problem says n<=1e7 doesn’t guarantees n=1e7. So with that re we can’t infer anything.
With second assert statement, it gives re so that means there are tc were n> 5*1e6.
You can try something like - assert n<1e7. If it gives re then we are sure there are tc where n=1e7.

1 Like

Gives error on cc IDE

1 Like

Thank You So much For the Explaination!
Now The Question Arises why using array for hashing passes in this Problem?
Because Array can access maximum index as [(10^6)-1] and how is it accessing [(10^7)-1] index?
Using Array Gives AC

I just ran on Codechef IDE it executes successfuly giving output as 3

Max size of array in main is between 1e6 to 1e7 according to this.

1 Like

Okay Thanks for it!
But Can You Tell why is this is running successfully?

1 Like

Sorry, no idea😶

1 Like

Okay No Issues!!

1 Like

Cool, I used map there when the contest was live, without knowing unordered_map would get TLE.
Thanks for telling.

2 Likes

Running this code locally gave segmentation fault, which was expected.
But on ideone it declares an array of size INT_MAX (due to 1e20 overflow prolly).
It prints a[n - 1] = 3, and the sizeof array = 8589934588.
link

1 Like

Thanks For this Information !