eolymp
bolt
Try our new interface for solving problems
Məsələlər

Matrix Transformation

Matrix Transformation

You have an integer matrix \textbf{A}, with \textbf{R} rows and \textbf{C} columns. That means it has \textbf{R} rows with each row containing \textbf{C }integers. Two integers are adjacent if their container cells share an edge. For example, in the following grid (\textbf{0}, \textbf{1}), (\textbf{4}, \textbf{5}), (\textbf{1}, \textbf{4}), (\textbf{5}, \textbf{2}) are adjacent but (\textbf{0}, \textbf{4}), (\textbf{2}, \textbf{6}), (\textbf{5}, \textbf{7}) are not adjacent. You are allowed to do only one kind of operation in the matrix. In each step you will select two adjacent cells and increase or decrease those two adjacent values by \textbf{1}, i.e., both values are increased by \textbf{1} or both values are decreased by \textbf{1}. Given a matrix, determine whether it is possible to transform it to a zero matrix by applying the allowed operations. A zero matrix is the one where each of its entries is zero. \InputFile The first input line contains a positive integer, \textbf{n}, indicating the number of matrices (test cases). Each matrix starts with a line containing \textbf{R} (\textbf{2} ≤ \textbf{R} ≤ \textbf{30}) and \textbf{C} (\textbf{2} ≤ \textbf{C} ≤ \textbf{30}) separated by a single space. Each of the next \textbf{R} lines contains \textbf{C} integers. Each of these integers is between \textbf{-20} and \textbf{+20} inclusive. Assume that each input matrix will have at least one non-zero value. \OutputFile For each test case output "\textbf{YES}" if you can transform it to a zero matrix or "\textbf{NO}" otherwise (capital letter only).
Zaman məhdudiyyəti 1 saniyə
Yaddaşı istafadə məhdudiyyəti 64 MiB
Giriş verilənləri #1
6
3 3
-2 2 2
1 1 0
2 -2 -2
3 3
-1 0 1
-2 -1 1
0 1 2
3 3
-1 0 1
0 2 -1
-1 1 2
3 3
-1 2 1
-1 -1 -3
1 1 -1
2 3
0 -2 3
1 3 1
2 3
3 1 1
2 0 1
Çıxış verilənləri #1
YES
NO
NO
YES
NO
YES
Mənbə ACM-ICPC Malaysia al-Khawārizmī Programming Contest 2011