Search
 
SCRIPT & CODE EXAMPLE
 

C

minimun number of moves in c

You are given an array a[0 ldots n-1]a[0…n−1] of length nn which consists of non-negative integers. Note that array indices start from zero.

An array is called good if the parity of each index matches the parity of the element at that index. More formally, an array is good if for all ii (0 le i le n - 10≤i≤n−1) the equality i mod 2 = a[i] mod 2imod2=a[i]mod2 holds, where x mod 2xmod2 is the remainder of dividing xx by 2.

For example, the arrays [0, 5, 2, 10,5,2,1] and [0, 17, 0, 30,17,0,3] are good, and the array [2, 4, 6, 72,4,6,7] is bad, because for i=1i=1, the parities of ii and a[i]a[i] are different: i mod 2 = 1 mod 2 = 1imod2=1mod2=1, but a[i] mod 2 = 4 mod 2 = 0a[i]mod2=4mod2=0.

In one move, you can take any two elements of the array and swap them (these elements are not necessarily adjacent).

Find the minimum number of moves in which you can make the array aa good, or say that this is not possible.
input
4
4
3 2 7 6
3
3 2 6
1
7
7
4 9 2 1 18 3 0
outout
2
1
-1
0
Comment

PREVIOUS NEXT
Code Example
C :: pointeur de pointeur en language c 
C :: table de hachage en c 
C :: temperature sensor data 
C :: jock cranley 
C :: kleiner gleich zeichen MAC 
C :: unigine 
C :: man write c 
C :: how to alias an awk command 
C :: assembly lea instruction 
C :: syntax of for loop in c stack over flow 
C :: Convert arduino String to C language String 
C :: c++ convert to c online 
C :: Single-line Comments in C 
C :: How to scale all columns in dataframe in R- Method 2? 
C :: return multiple values using the call by reference 
C :: cannot reach esp8266 via udp while he is running with a static ip 
C :: or gmode inline image 
C :: online c compiler 
C :: Word Processor, Spreadsheet and Presentation Software are the examples of 
C :: split string at space C 
C :: how to stop scanf from adding a new line in c 
C :: get configuration script window 7 
Dart :: circle avatar from image asset flutter 
Dart :: How to Create Number Inputfield in Flutter? 
Dart :: flutter text color 
Dart :: FirebaseOptions cannot be null when creating the default app 
Dart :: image from internet flutter 
Dart :: Round button with text and icon in flutter 
Dart :: how to make appbar transparent in flutter 
Dart :: dart convert int string leading zeros 
ADD CONTENT
Topic
Content
Source link
Name
6+6 =