CF217C.Formurosa

省选/NOI-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

The Bytelandian Institute for Biological Research (BIBR) is investigating the properties of two species of bacteria, named simply 0 and 1. Even under a microscope, bacteria of those two species are very difficult to distinguish. In fact, the only thing the scientists possess that is able to differentiate between them is a plant called Formurosa.

If the scientists place a sample of colonies of bacteria on each on Formurosa's leaves, it will activate a complicated nutrition process. During that process color of Formurosa changes to reflect the result of a — possibly very complicated — logical formula on the species of bacteria, involving constants and the operators | (OR), & (AND) and ^ (XOR). If it is 0, the plant will turn red, otherwise — it will turn blue.

For example, if the nutrition process of Formurosa is described by the formula: (((??)|?)&(1?)); then Formurosa has four leaves (the "?" signs denote the leaves). If we place 0, 1, 0, 0 on the respective leaves, the result of the nutrition process will be (((01)|0)&(10)) = 1, therefore the plant will turn blue.

The scientists have n colonies of bacteria. They do not know their types; the only thing they know for sure is that not all colonies are of the same type. They want to attempt to determine the bacteria's species by repeated evaluations with Formurosa. During each evaluation they must place exactly one sample on every leaf of the plant. However, they may use multiple samples of one colony during a single evaluation; they can even cover the whole plant with bacteria from one colony!

Is it possible for them to always determine the species of each colony, no matter what they are (assuming they are not all the same)?

Byteland 生物研究所(BIBR)正在研究两种细菌物种的特性,这两种细菌被简单地命名为 0 和 1。即使在显微镜下,这两种细菌也极难区分。事实上,科学家们手中唯一能区分它们的工具是一种名为 Formurosa 的植物。

若科学家将若干细菌菌落样本分别置于 Formurosa 的每一片叶子上,该植物便会启动一个复杂的营养过程。在此过程中,Formurosa 的颜色将根据作用于这些细菌物种(即输入为 0 或 1)的一个——可能非常复杂的——逻辑公式而变化;该公式可包含常数以及运算符 |(OR)、&(AND)和 ^(XOR)。若公式的计算结果为 0,植物将变为红色;否则(即结果为 1),植物将变为蓝色。

例如,若 Formurosa 的营养过程由公式 (((?^?)|?)&(1^?)) 描述,则 Formurosa 共有四片叶子(其中 ? 符号表示叶子位置)。若我们在各叶子上依次放置 0、1、0、0,则营养过程的结果为 (((0^1)|0)&(1^0)) = 1,因此植物将变为蓝色。

科学家们拥有 nn 个细菌菌落。他们并不知道每个菌落的具体类型;唯一确定的事实是:并非所有菌落都属于同一类型。他们希望通过多次使用 Formurosa 进行测试,来确定每个菌落的种类。在每次测试中,他们必须在 Formurosa 的每一片叶子上恰好放置一个样本。然而,他们在单次测试中可以多次使用同一个菌落的样本;甚至可以整株植物全部用来自同一菌落的细菌覆盖!

问题:无论这 nn 个菌落的实际类型如何(仅已知它们不全相同),科学家们是否总能通过上述方式,准确判定出每一个菌落的种类?

输入格式

The first line of input contains a single integer n (2 ≤ n ≤ 106) — the number of colonies of bacteria.

The second line contains the formula describing the nutrition process of Formurosa. This line contains only characters «0», «1», «?», «|», «&», «^», «(», «)» and complies with the following grammar:

s → 0|1|?|(s|s)|(s&s)|(s^s)

The formula consists of no more than 106 characters.

输入的第一行包含一个整数 nn(2≤n≤1062 \leq n \leq 10^6)——表示细菌菌落的数量。

第二行包含描述 Formurosa 营养过程的公式。该行仅包含字符 0、1、?、|、&、^、(、),并满足如下文法:

s→0∣1∣?∣(s∣s)∣(s&s)∣(s∧s)s \to 0 \mid 1 \mid ? \mid (s \mid s) \mid (s \& s) \mid (s \wedge s)

该公式长度不超过 10610^6 个字符。

输出格式

If it is always possible to determine the species of each colony, output "YES" (without quotes). Otherwise, output "NO" (without quotes).

如果总能确定每个菌落的物种,则输出 “YES”(不带引号)。否则,输出 “NO”(不带引号)。

输入输出样例

  • 输入#1

    2
    (?^?)

    输出#1

    NO
  • 输入#2

    10
    ?

    输出#2

    YES
  • 输入#3

    2
    ((?^?)&?)

    输出#3

    YES

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

首页