IOI '14 - Taipei, Taiwan
Move from one station to another
Taiwan has a rail system that connects all train stations. The rail
system has
Jian-Jia wants to travel through Taiwan along this railway system.
Jian-Jia will start from the first station and stop at the last
station. Since Jian-Jia bought a discount ticket, he can only travel at
most
Example
We assume that there are
Statement
Given the locations of all stations with lodge service and the limit
Input Specification
- Line 1: two integers
and , the number of stations and the limit; - Line 2:
lodge[0]
, …,lodge[n-1]
lodge
is the array indicating whether a station has lodge service. For example, if station has lodge service, thenlodge[i]
will be , and otherwise. We assume that bothlodge[0]
andlodge[n-1]
are .
Output Specification
The output should contain one integer – the minimum number of days for
Jian-Jia to travel from the first station to the last station if
possible. If not possible, then output -1
.
Sample Input 1
11 3
1 1 0 0 1 1 0 1 0 0 1
Sample Output 1
4
Sample Input 2
13 3
1 0 0 0 1 0 0 1 0 0 0 0 1
Sample Output 2
-1
Comments