|시간 제한||메모리 제한||제출||정답||맞은 사람||정답 비율|
|1 초||512 MB||1||1||1||100.000%|
Dreamoon serves in the military this year. Everything in the military is boring. In order to make military life more interesting, Dreamoon decided to transform some of his military experiences into programming competition problems.
The leaders usually order soldiers to stand in several rows ordered by their heights. The rules of arrangement of soldiers are as follows:
After Dreamoon noticed these properties, the following problem came to his mind:
For two different soldiers $A$ and $B$, we say $B$ is right front of $A$ if $A$'s row is NOT in front of the $B$'s row, and the number of soldiers to the right of $B$ in $B$'s row is not larger than the number of soldiers to the right of $A$ in $A$'s row.
You don't know how many soldiers there are in total, and you don't know how many rows these soldiers are arranged into. But you have some information about certain $N$ soldiers, numbered from $1$ through $N$. You are given the heights of these soldiers. And for any two distinct numbers $i$ and $j$, you know whether soldier $j$ is right front of $i$. Please inspect whether there exists at least one possible configuration satisfying the given information. If possible, you should calculate the minimum number of soldiers in the first row (the row in front of every other row).
The first line of input contains one integer $N$ indicating that you have information of $N$ soldiers. The second line of input consists of $N$ integers $h_1, h_2, \ldots, h_N$. Here, $h_i$ indicates the height of $i$-th soldier. Each of the following $N$ lines contains $N$ characters. The $j$-th character in the $i$-th of these lines is '
1' if soldier $j$ is right front of soldier $i$; otherwise, it is '
Output one number indicating the minimum possible number of soldiers in the first row (the row in front of every other row). If there is no possible configuration satisfying the given information, output $-1$ instead.
0' or '
0' for all $i$ in $1, 2, \ldots, N$
3 1 2 3 000 000 000
3 1 2 3 000 100 110