#P7309. [COCI 2018/2019 #2] Kocka
[COCI 2018/2019 #2] Kocka
Description
You are given an matrix. Some cells are blocked, and some cells are empty. During observation, he looks at the matrix from directions.
First, he looks from the left side. For each row, he records how many empty cells appear before the first blocked cell. If there is no blocked cell in that row, he records . Then he does the same from the right side, the top side, and the bottom side, and records the results.
In total, he wrote down numbers, with numbers for each direction. However, an unknown villain destroyed the matrix, and all that remains are the numbers he wrote down.
You need to determine whether there is any mistake in these numbers, that is, whether it is possible to reconstruct an matrix consistent with these numbers.
Input Format
The first line contains a positive integer , the size of the matrix.
The second line contains integers , the recorded numbers when observing from the left.
The third line contains integers , the recorded numbers when observing from the right.
The fourth line contains integers , the recorded numbers when observing from the top.
The fifth line contains integers , the recorded numbers when observing from the bottom.
Output Format
If the given numbers can correspond to some matrix, output DA. Otherwise, output NE.
3
-1 2 0
-1 0 1
2 2 1
0 0 1
DA
3
-1 0 1
-1 2 1
-1 2 -1
1 0 -1
NE
Hint
Explanation for Sample 1

Constraints
For of the testdata, .
For of the testdata, , .
Notes
The score of this problem follows the original COCI setting, with a full score of .
Translated from COCI2018-2019 CONTEST #2 T2 Kocka.
Translated by ChatGPT 5
京公网安备 11011102002149号