#P5639. 【CSGRound2】守序者的尊严
【CSGRound2】守序者的尊严
Description
Xiao Z, a friend of zhouwc (the “my friend is actually me” kind), cannot bear the hunger and has to take the risk of ordering delivery.
However, to catch students who order delivery, Director Q set up a tight net—cameras.
But because the school’s budget for Director Q is limited, these cameras cannot work continuously. After working for one second, they must stop and rest for one second, that is, after being on for one second, they turn off for one second, then on for one second... and so on.
Also due to limited budget, these cameras are arranged in a straight line, which lies on the only path students must take to reach the delivery pickup point—the Gate 2 (with no guard).
Because Xiao Z has learned a sprint skill, the time for him to pass through any number of cameras that are turned off is (that is, in one move he can pass through several cameras that are not on).
Since Xiao Z wants to eat delivery food but does not want to be punished by Director Q watching in the control room, please tell him the minimum time needed to safely reach the pickup point.
Input Format
There are lines in total.
The first line contains a positive integer , meaning there are cameras on this road.
The second line contains numbers, representing the on/off states of these cameras at time seconds. means a camera is off, and means it is on. It is guaranteed that the first camera is off.
Output Format
Output one line, the time required for Xiao Z to safely reach the delivery pickup point.
6
0 0 1 1 0 1
4
6
0 0 0 0 0 0
1
Hint
Constraints
For of the testdata, .
For of the testdata, .
For of the testdata, .
For of the testdata, .
For of the testdata, .
The camera states are all represented using and .
Sample Explanation 1
In the first second, Xiao Z rushes to the second camera, taking second, for a total time of second.
In the second second, the camera states become .
At this time, Xiao Z quickly rushes from the second camera to the fourth camera, taking second, for a total time of seconds.
In the third second, the camera states become .
At this time, Xiao Z quickly rushes from the fourth camera to the fifth camera, taking second, for a total time of seconds.
In the fourth second, the camera states become .
At this time, Xiao Z quickly rushes from the fifth camera and leaves the monitored area, taking second, for a total time of seconds.
Sample Explanation 2
In the first second, Xiao Z rushes out of the monitored area directly.
Translated by ChatGPT 5
京公网安备 11011102002149号