Emma is playing a new mobile game involving clouds numbered from to . A player initially starts out on cloud , and they must jump to cloud . In each step, she can jump from any cloud to cloud or cloud .
There are two types of clouds, ordinary clouds and thunderclouds. The game ends if Emma jumps onto a thundercloud, but if she reaches the last cloud (i.e., ), she wins the game!
Can you find the minimum number of jumps Emma must make to win the game? It is guaranteed that clouds and are ordinary-clouds and it is always possible to win the game.
Input Format
The first line contains an integer, (the total number of clouds).
The second line contains space-separated binary integers describing clouds .
The second line contains space-separated binary integers describing clouds .
- If , the cloud is an ordinary cloud.
- If , the cloud is a thundercloud.
Constraints
Output Format
Print the minimum number of jumps needed to win the game.
Sample Input 0
Sample Input 0
7
0 0 1 0 0 1 0
Sample Output 04
Sample Input 16
0 0 0 0 1 0
Sample Output 13
Explanation
Sample Case 0: Because and in our input are both , Emma must avoid and . Bearing this in mind, she can win the game with a minimum of jumps:
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <stdbool.h>
int main(){
int n;
scanf("%d",&n);
int *c = malloc(sizeof(int) * n);
for(int c_i = 0; c_i < n; c_i++){
scanf("%d",&c[c_i]);
}
int temp = 0,count = 0;
while (temp<n-1)
{
if (c[temp+2]==0 && (temp+2<=n))
{count = count +1;
temp = temp +2;
}
else if (c[temp+1]==0)
{
count = count +1;
temp = temp +1;
}
}
printf("%d",count);
return 0;
}
No comments:
Post a Comment