WHY THIS CODE DIDN'T ACCEPTED DURING COOK-A-CODE

please don’t joke this is not a platform to joke
if you can hep us please help otherwise move forward

@anon44231457 Yes, i can help you. there is a wrong in your answer. the solution should be in O(1) but i don’t think your solution followed that formation.

just check it once it is O(1)

@anon44231457 in your first else why didn’t you give indentation?

         if(n<=k)
        {
           cout<<"A\n";            
        }
        else
        {
        if((n)%(k+1)==0)
        {
            cout<<"B\n";
        }
        else

can you explain briefly??
It is a c++ code not python

Yes, i was wrong. I think I have to analysis the logic carefully. I will find the mistake soon and then tell you.

Just add this line after cin>>n>>k; and try

assert(n>0);

2 Likes

but why??
i have never use this assert
please tell me about this

How did you submit it now ?
The problems are not yet made public ??

but why the other code got accepted. that also doesn’t have any assert thing…
please reply… @sunil5798

his submission time was 2020-03-02 00:04:08

1 Like

If n=0 then your code and accepeted code will give different results.
According to constraints n should not be 0.
But what if wrong test cases?

2 Likes

the submission is during contest

1 Like

I guess it has something to do with the brackets in the if statement of the else part.
Try if((n%(k+1))==0) and then try to submit.

but in the constraint n>=1

@akash19jain how is that even possible that brackets make answer wrong … pls dont guess…

There does not look any error.
So we can only guess.:smile:

3 Likes

Wow, how can you say that the brackets don’t make an answer wrong. There are multiple cases when because of the brackets, the answer received is different from than what was expected.
And I am not just making a random guess but an educated guess looking at the results.
I can only confirm once the problem is moved to practice and I can make some manipulations and submit his program.

5 Likes

but in that particular code all brackets are correct… i didnt said that in general…

This seems the most likely explanation to me.

2 Likes