Runtime error in CENS20G - Help Please

Share the link to your submission.
Go to problems page->My Submissions

1 Like

here is my solution link:

it will fail when one/some of the keys ‘U’, ‘L’, ‘R’, and ‘D’ is/are missing. For eg, if in the string, there is no ‘U’ character, calling m[‘U’] will raise runtime error, since the key won’t be there in the hashmap.

1 Like

Intialize with U D L R all as 0

1 Like

That does not cause a problem. It automatically return value as 0


It should be map<char,ll> not map<ll,ll>

1 Like

Also, you do not need to use ll

1 Like

here is my solution

1 Like

Guys thanks for help-:
i changed map<char,int> m;
and it works

Why should we use like that. Characters can be represented as numbers right? Why is it giving Runtime error?

There’s no reason that I can see why using map<ll,ll> m; should break things (it’s merely a weird thing to do :))

The actual problem seems to be this:

    int t; cin>>t;

i.e. calling sync_with_stdio after reading input.

From here:


Thank you!

1 Like

okay… thats the correct reason!! nice :upside_down_face:

If he uses key as ll shouldn’t be also access keys with the ASCII code?

Yes - the char should be implicitly converted to ll which has the ASCII value of the char, so I think it should work - at least, I can’t think of any situation where it shouldn’t.

1 Like

hi… but what if we post the same solution in c++17 and not in c++14 ??
I am confused … is there any difference coz i submitted same soln in c++17 and it shows AC

There’s Implementation-defined Behaviour for you :man_shrugging:

1 Like

Do you know how maps work?

@therealnishuz enlighten me

Your reason is wrong.