#P9797. [NERC 2018] Guest Student
[NERC 2018] Guest Student
Background
Translated from Problem G of NERC 2018.
Problem Description
As a guest student at a well-known university, you want to attend classes. Unfortunately, in each week you are only available at certain times to attend classes. If , it means you are available in week ; otherwise you are not.
You need to arrange a schedule so that the time from attending the first class to attending the last class is as short as possible. Of course, you can decide on which available time you attend the first class.
Input Format
The first line contains an integer , the number of test cases.
For each test case, the first line contains an integer .
Then follow integers , where means available and means not available.
Output Format
For each test case, output one integer, the minimum time from the first class to the last class.
3
2
0 1 0 0 0 0 0
100000000
1 0 0 0 1 0 1
1
1 0 0 0 0 0 0
8
233333332
1
Hint
For all testdata, it is guaranteed that , , and .
For sample 1, if you start attending classes from Tuesday and attend until next Tuesday, days pass.
Translated by ChatGPT 5