Customized Chess Board

  • + 0 comments
    #!/bin/python3
    
    import math
    import os
    import random
    import re
    import sys
    
    # Complete the solve function below.
    def solve(board):
        res = []
        p_el = None
        flag = False
        for i in board:
            count = 0
            prv = None
            for j in i:
                if count == 0:
                    if j == p_el:
                        flag = True
                        break
                    else:
                        p_el = j
                count += 1
                if prv == j:
                    flag = True
                    break
                prv = j
            if flag:
                res.append('No')
                break
        if not flag:
            res.append('Yes')
        return res[0]
            
                
                
    if __name__ == '__main__':
        fptr = open(os.environ['OUTPUT_PATH'], 'w')
    
        t = int(input().strip())
    
        for t_itr in range(t):
            n = int(input().strip())
    
            board = []
    
            for _ in range(n):
                board.append(list(map(int, input().rstrip().split())))
    
            result = solve(board)
    
            fptr.write(result + '\n')
    
        fptr.close()