EIU ICPC Contest 2026 - F: Positive Product

Xem dạng PDF

Gửi bài giải

Điểm: 1,00
Giới hạn thời gian: 1.0s
Giới hạn bộ nhớ: 256M
Input: stdin
Output: stdout

Nguồn bài:
Châu Nhật Tăng
Dạng bài
Ngôn ngữ cho phép
C, C++, Java, Kotlin, Pascal, PyPy, Python, Scratch

During a math class, Tang was given an array of ~N~ integers ~A_1, A_2, \dots, A_N~. Being fond of "harmonious" numbers, Tang wants to transform this array so that the product of any two distinct elements is always a positive integer. In other words, for every pair of indices ~(i, j)~ satisfying ~1 \le i < j \le N~, the condition ~A_i \times A_j > 0~ must hold.

To achieve this, Tang can perform the following operation any number of times (possibly zero):

  • Choose an index ~i~ ~(1 \le i \le N)~ and negate the element ~A_i~ (replace ~A_i~ with ~-A_i~).

Tang really wants to know the minimum number of operations required to make the array satisfy the condition. Help Tang calculate this minimum number of operations, or report if it is impossible to achieve!

Input

  • The first line contains an integer ~N~ ~(2 \le N \le 100)~ — the number of elements in array ~A~.
  • The second line contains ~N~ integers ~A_1, A_2, \dots, A_N~ ~(-1000 \le A_i \le 1000)~ — the elements of array ~A~.

Output

  • Print a single integer representing the minimum number of operations needed. If it is impossible to transform the array to satisfy the requirement, print ~-1~.

Sample Input 1

5
10 -20 -30 40 50

Sample Output 1

2

Sample Input 2

4
9 7 2 3

Sample Output 2

0

Sample Input 3

3
0 0 0

Sample Output 3

-1

Explanation

  • In the first sample, we can negate the elements at indices ~2~ and ~3~. The array becomes ~[10, 20, 30, 40, 50]~, where the product of any two elements is greater than ~0~, requiring a minimum of ~2~ operations.

Bình luận

Hãy đọc nội quy trước khi bình luận.


Không có bình luận tại thời điểm này.