We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.

I divided this problem into 2 cases: when Q is even and odd. And the code below is what I wrote just for the even cases. It worked correctly for the test case #0 where P=3 and Q=2; however, I received an X on the test case #16 where P=3505 and Q=2. My code should print one of the correct answers for the test #16 as well, but somehow I got a cross. Would anyone here have an idea why this is hapenning? I would appreciate your help.

#!/bin/python3importsysdefprintTopRow(num):foriinrange(num):print(i+1,i+2)defprintLowerRows(P,Q,b):foriinrange(P):forjinrange(int(Q/2)):ifj==0:print(int(Q/2)+1+i*Q,b+1+i*int(Q/2))else:print(b+i*int(Q/2)+j,b+i*int(Q/2)+j+1)if__name__=="__main__":P,Q=map(int,input().split())ifQ%2==0:"""Case 1: Q is even"""m=int((3/2)*P*Q)n=m+1biggest=P*Q+1print(n,m)printTopRow(biggest-1)printLowerRows(P,Q,biggest)else:"""Case 2: Q is odd"""pass

## Lovely Triplets

You are viewing a single comment's thread. Return to all comments →

I divided this problem into 2 cases: when Q is even and odd. And the code below is what I wrote just for the even cases. It worked correctly for the test case #0 where P=3 and Q=2; however, I received an X on the test case #16 where P=3505 and Q=2. My code should print one of the correct answers for the test #16 as well, but somehow I got a cross. Would anyone here have an idea why this is hapenning? I would appreciate your help.