CF416A.Guess a number!

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

A TV show called "Guess a number!" is gathering popularity. The whole Berland, the old and the young, are watching the show.

The rules are simple. The host thinks of an integer y and the participants guess it by asking questions to the host. There are four types of acceptable questions:

  • Is it true that y is strictly larger than number x?
  • Is it true that y is strictly smaller than number x?
  • Is it true that y is larger than or equal to number x?
  • Is it true that y is smaller than or equal to number x?

On each question the host answers truthfully, "yes" or "no".

Given the sequence of questions and answers, find any integer value of y that meets the criteria of all answers. If there isn't such value, print "Impossible".

一档名为“猜数字!”的电视节目正日益流行,整个贝尔兰,无论老少,都在收看该节目。

游戏规则很简单:主持人会想好一个整数 yy,参与者通过向主持人提问来猜测这个数字。允许提出的问题共有四种类型:

  • yy 是否严格大于数字 xx?
  • yy 是否严格小于数字 xx?
  • yy 是否大于或等于数字 xx?
  • yy 是否小于或等于数字 xx?

对于每个问题,主持人都会如实回答“是”或“否”。

给定一系列问题及其答案,请找出任意一个满足所有答案条件的整数 yy。若不存在这样的整数,则输出 "Impossible"。

输入格式

The first line of the input contains a single integer n (1 ≤ n ≤ 10000) — the number of questions (and answers). Next n lines each contain one question and one answer to it. The format of each line is like that: "sign x answer", where the sign is:

  • ">" (for the first type queries),
  • "<" (for the second type queries),
  • ">=" (for the third type queries),
  • "<=" (for the fourth type queries).

All values of x are integer and meet the inequation  - 109 ≤ x ≤ 109. The answer is an English letter "Y" (for "yes") or "N" (for "no").

Consequtive elements in lines are separated by a single space.

输入的第一行包含一个整数 nn(1≤n≤100001 \leq n \leq 10000)—— 表示问题(及对应答案)的数量。接下来的 nn 行,每行包含一个问题及其对应答案。每行的格式为:“sign x answer”,其中 sign 是:

  • “>”(表示第一类查询),
  • “<”(表示第二类查询),
  • “>=”(表示第三类查询),
  • “<=”(表示第四类查询)。

所有 xx 的取值均为整数,且满足不等式 −109≤x≤109-10^9 \leq x \leq 10^9。answer 是一个英文字母:“Y”(表示“是”)或 “N”(表示“否”)。

每行中相邻元素之间以单个空格分隔。

输出格式

Print any of such integers y, that the answers to all the queries are correct. The printed number y must meet the inequation  - 2·109 ≤ y ≤ 2·109. If there are many answers, print any of them. If such value doesn't exist, print word "Impossible" (without the quotes).

输出任意一个满足所有查询答案正确的整数 yy。输出的数字 yy 必须满足不等式 −2⋅109≤y≤2⋅109-2\cdot10^9 \leq y \leq 2\cdot10^9。若存在多个解,输出其中任意一个即可。若不存在这样的值,则输出单词 "Impossible"(不带引号)。

输入输出样例

  • 输入#1

    4
    &gt;= 1 Y
    &lt; 3 N
    &lt;= -3 N
    &gt; 55 N

    输出#1

    17
  • 输入#2

    2
    &gt; 100 Y
    &lt; -100 Y

    输出#2

    Impossible

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

首页