WA in CONFLIP

Solution:
https://www.codechef.com/viewsolution/30967750
Kindly check and let me know which cases I am missing?

try:
    T = int(input())
    for _ in range(T):
        G = int(input())
        for m in range(G):
            INQ = list(map(int,input().split()))
            I = INQ[0]
            N = INQ[1]
            Q = INQ[2]
            n = N%2
            temp = int(N/2)
            if n == 0:
                print(N/2)
            else:
                if I == 1 :
                    if Q == 1:
                        print(temp)
                    else:
                        print(temp+1)
                else:
                    if Q == 2 :
                        print(temp)
                    else:
                        print(temp+1)
except EOFError:
    pass

Access denied , you don’t have permission to view this page.

Seems some issue, added code in the description

@shreya_cc2020
use floor division for n = 0
because in python
4/2 = 2.0
4//2 = 2

1 Like

@shreya_cc2020 While running your code on the following test-cases, I got the following output:

Test-Cases:
5
2
1 5 1
1 5 2
2
1 1 1
2 1 1
2
1 3 1
2 3 1
2
1 4 1
2 4 1
5
2 5 1
2 5 2
1 1 2
2 1 2
2 4 2
Your Code Ouput:
2
3
0
1
1
2
2.0
2.0
3
2
1
0
2.0

I suppose you know now what are you doing wrong. In python do remember that there are two kinds of division operators (/ and //). / is for real number division and // for integer division. You can fire up your python interpreter to know the difference between the two.

Updated/Accepted Code is as follows:

try:
    T = int(input())
    for _ in range(T):
        G = int(input())
        for m in range(G):
            INQ = list(map(int,input().split()))
            I = INQ[0]
            N = INQ[1]
            Q = INQ[2]
            n = N % 2
            temp = N // 2
            if n == 0:
                print(N // 2)
            else:
                if I == 1 :
                    if Q == 1:
                        print(temp)
                    else:
                        print(temp+1)
                else:
                    if Q == 2 :
                        print(temp)
                    else:
                        print(temp+1)
except EOFError:
    pass

However, you can optimize and write your code in a more pythonic way as:

def main():
    for test in range(int(input().strip())):
        number_of_games_played = int(input().strip())
        for game in range(number_of_games_played):
            initial_state, number_of_rounds, prediction = tuple(map(int, input().strip().split()))
            if not number_of_rounds % 2 or initial_state == prediction:
                print("{}".format(number_of_rounds >> 1))
                continue
            print("{}".format((number_of_rounds >> 1) + 1))

if __name__ == "__main__":
    main()
2 Likes

Thanks, duly noted!

Thanks!