CF353A.Domino

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Valera has got n domino pieces in a row. Each piece consists of two halves — the upper one and the lower one. Each of the halves contains a number from 1 to 6. Valera loves even integers very much, so he wants the sum of the numbers on the upper halves and the sum of the numbers on the lower halves to be even.

To do that, Valera can rotate the dominoes by 180 degrees. After the rotation the upper and the lower halves swap places. This action takes one second. Help Valera find out the minimum time he must spend rotating dominoes to make his wish come true.

瓦列拉有一排 nn 个多米诺骨牌。每块骨牌由两个半片组成——上半片和下半片。每个半片上写有一个 11 到 66 之间的整数。瓦列拉非常喜欢偶数,因此他希望所有上半片上的数字之和为偶数,且所有下半片上的数字之和也为偶数。

为此,瓦列拉可以将任意多米诺骨牌旋转 180∘180^\circ。旋转后,上半片与下半片的位置互换。每次旋转耗时一秒。请帮助瓦列拉找出使其愿望达成所需的最少旋转时间。

输入格式

The first line contains integer n (1 ≤ n ≤ 100), denoting the number of dominoes Valera has. Next n lines contain two space-separated integers x__i, y__i (1 ≤ x__i, y__i ≤ 6). Number x__i is initially written on the upper half of the i-th domino, y__i is initially written on the lower half.

第一行包含一个整数 nn(1≤n≤1001 \leq n \leq 100),表示瓦莱拉拥有的多米诺骨牌数量。接下来的 nn 行每行包含两个用空格分隔的整数 xix_i、yiy_i(1≤xi,yi≤61 \leq x_i, y_i \leq 6)。其中,xix_i 初始时写在第 ii 张多米诺骨牌的上半部分,yiy_i 初始时写在下半部分。

输出格式

Print a single number — the minimum required number of seconds. If Valera can't do the task in any time, print  - 1.

输出一个整数——完成任务所需的最少秒数。如果瓦列拉无法在任何时间内完成该任务,则输出 -1。

输入输出样例

  • 输入#1

    2
    4 2
    6 4

    输出#1

    0
  • 输入#2

    1
    2 3

    输出#2

    -1
  • 输入#3

    3
    1 4
    2 3
    4 4

    输出#3

    1

说明/提示

In the first test case the sum of the numbers on the upper halves equals 10 and the sum of the numbers on the lower halves equals 6. Both numbers are even, so Valera doesn't required to do anything.

In the second sample Valera has only one piece of domino. It is written 3 on the one of its halves, therefore one of the sums will always be odd.

In the third case Valera can rotate the first piece, and after that the sum on the upper halves will be equal to 10, and the sum on the lower halves will be equal to 8.

在第一个测试用例中,上半部分数字之和为 10,下半部分数字之和为 6。这两个数均为偶数,因此瓦莱拉无需进行任何操作。

在第二个样例中,瓦莱拉只有一张多米诺骨牌,其一半上写有数字 3,因此两个和中必有一个为奇数。

在第三个用例中,瓦莱拉可以将第一张多米诺骨牌旋转,旋转后上半部分数字之和为 10,下半部分数字之和为 8。

输入解题思路,AI测评打分。不知道怎么写?

首页