AC solution in Python for Chef the Brave Warrior.

Can someone please provide the AC solution of Chef the brave Warrior in python. I have submitted this https://www.codechef.com/viewsolution/13102468 solution but getting runtime error, don’t know whats wrong.

2 Likes

I have tried every possibility. And i am assure that problem is not in taking the input. The problem is in printing the output. Even i have tried operator module and bits manipulation method but it’s still showing either WA or RE.

There is no bug in test cases. I think only expert can answer your query, so please wait or try other questions till then. If you wanna look the clean and neat solution in C++ then click here.

Looking for it in python…let u know

yup…! the same solution is working fine for java with bigint.

The same code is working fine in hackerrank compiler (Python 2 I guess)

Compilation Successful
Input (stdin)
7 3
Your Output
4
odd

Are you entering correct version of language? If yes, then did you try re-submitting? It might be a glitch, I would advise contact admins regarding this.

EDIT- This reminds me when using Scanner was giving error in “Code, Compile and Run”, and the weird fact was that the bug disappeared automatically after ~45 minutes.

1 Like

I submitted code for this que for about 3 times and others are still trying you can see the submissions for this question and the problem is that it is working fine for java and c++ code but not for python.

1 Like

I hope test cases don’t contain any case with integers in separate line (That would give an error). @meooow pointed in one thread that test case had input of ~10^24 when constraints specified input being less than 10^19. I feel its either a bug or flaw of test case. Aside from that, I fear I am unable help you further. I sincerely hope that your query gets resolved asap!

1 Like

@vijju123
My python solution is also working fine on compiler but the problem is of input numbers 10^25…

But if I am not wrong, python is able to handle overflow nicely. Can you elaborate on why you feel its input? :slight_smile:

1 Like

Because solution is not getting accepted…admin can help!!

1 Like

Yup. @admin, can you help us here please? :slight_smile:

2 Likes

I modified your code a little.

This python solution gets an AC.

Have fun! :slight_smile:

EDIT: Just to clarify all I have done is applied some tricks that try to combat badly formatted input. Having used python for a while, I have across this issue often. (even in Official Long challenges sometimes)

Brief rundown: You create an empty string x. You keep appending any input to it till EOF using an infinite while loop. You further append two zeroes to it. Then take the first two integers in the string x.

The first one is obvious, input being on separate lines or even empty lines in between. The second is to combat an empty test case. AFAIR, C++ would read in zeroes for any non existent input, so I am working under the assumption that problem was tested with C++. This was a first attempt so maybe appending zeroes isn’t necessary. Just tried to cover all cases.

4 Likes

Can you explain what was the mistake>?

Edited the answer. Hope it makes sense.

So can you please specify which test case is it failing or giving RE?

I don’t know. As in, I can’t see what the test cases are.

Thank you for solving this question, but seriously it is weird that this simple question was not giving AC for that solution.please share if you know what was wrong with that solution.

1 Like

Thanks to @grebnesieh, i got it! The problem is in test cases. There must be a test case which is not in a single line. According to the code provided by him, if i remove appended 0,0 then their code is also giving AC. Since their is definitely a test case which is not in a single line.

no bug in test cases,check ur code

Thanks dude!! Your help is really appreciated !!! Also, harry, I think by “modified code a little” he meant he modified code to work for the badly formatted input/test-case