NC222453. [USACOJan2021G]Telephone
描述
输入描述
The first line contains N and K.
The next line contains N space-separated integers b1,b2,…,bN.
The next K lines describe the matrix S. Each consists of a string of K bits, Sij being the jth bit of the ith string from the top.
输出描述
Print a single integer giving the minimum amount of time needed. If it is impossible to transmit the message from cow 1 to cow N, then output −1.
示例1
输入:
5 4 1 4 2 3 4 1010 0001 0110 0100
输出:
6
说明:
The optimal sequence of transmissions is 1→4→3→5. The total amount of time is |1−4|+|4−3|+|3−5|=6.