Solutions are presented as using the least memory and the fastest execution time. It also takes the top 10 most recent solutions from each language. If you want to limit to a specific index, click the "Solved" button and go to that problem.
ContestId |
Name |
Phase |
Frozen |
Duration (Seconds) |
Relative Time |
Start Time |
---|---|---|---|---|---|---|
1367 | Codeforces Round 650 (Div. 3) | FINISHED | False | 7200 | 139505099 | June 16, 2020, 2:35 p.m. |
Solved$ |
Index |
Name |
Type |
Tags |
Community Tag |
Rating |
---|---|---|---|---|---|---|
( 54233 ) | B | Even Array | PROGRAMMING | greedy math |
B'You are given an array a[0 ldots n-1] of length n 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 i ( 0 <= i <= n - 1 ) the equality i bmod 2 = a[i] bmod 2 holds, where x bmod 2 is the remainder of dividing x by 2. For example, the arrays [ 0, 5, 2, 1 ] and [ 0, 17, 0, 3 ] are good, and the array [ 2, 4, 6, 7 ] is bad, because for i=1 , the parities of i and a[i] are different: i bmod 2 = 1 bmod 2 = 1 , but a[i] bmod 2 = 4 bmod 2 = 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 a good, or say that this is not possible. The first line contains a single integer t ( 1 <= t <= 1000 ) -- the number of test cases in the test. Then t test cases follow. Each test case starts with a line containing an integer n ( 1 <= n <= 40 ) -- the length of the array a . The next line contains n integers a_0, a_1, ldots, a_{n-1} ( 0 <= a_i <= 1000 ) -- the initial array. For each test case, output a single integer -- the minimum number of moves to make the given array a good, or -1 if this is not possible. In the first test case, in the first move, you can swap the elements with indices 0 and 1 , and in the second move, you can swap the elements with indices 2 and 3 . In the second test case, in the first move, you need to swap the elements with indices 0 and 1 . In the third test case, you cannot make the array good. '... |
Codeforces Round #650 (Div. 3) Editorial |
No solutions yet.