cf 447 div2 Ralph And His Magic Field

codeforces
combinators
math

#1

i have understood the formula for it but i am unable to understand that when k=-1 and n and m have different parity the answer will be -1 but for k=1 answer will not be -1 why?
problem


#2

This comment shall answer your question.


#3

if we multiply all rows’s product then they should be equal to multiplication of all element in the matrix same for columns. if n and m have different parity lets say n is even and m is odd then when we multiply all row’s product we get even number because each row’s product is equal to -1 but when we multiply all column’s product then we get odd number but both should be equal to multiplication of all elements in the matrix that’s why for k=-1 if n and m have different parity then solution does not exist…