CF778B.Bitwise Formula

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

The first line contains two integers nn and mm , the number of variables and bit depth, respectively ( 1<=n<=50001<=n<=5000 ; 1<=m<=10001<=m<=1000 ).

The following nn lines contain descriptions of the variables. Each line describes exactly one variable. Description has the following format: name of a new variable, space, sign ":=", space, followed by one of:

  1. Binary number of exactly mm bits.
  2. The first operand, space, bitwise operation ("AND", "OR" or "XOR"), space, the second operand. Each operand is either the name of variable defined before or symbol '?', indicating the number chosen by Peter.

Variable names are strings consisting of lowercase Latin letters with length at most 10. All variable names are different.

输入格式

In the first line output the minimum number that should be chosen by Peter, to make the sum of all variable values minimum possible, in the second line output the minimum number that should be chosen by Peter, to make the sum of all variable values maximum possible. Both numbers should be printed as mm -bit binary numbers.

输出格式

In the first sample if Peter chooses a number 0112011_{2} , then a=1012,b=0112,c=0002a=101_{2},b=011_{2},c=000_{2} , the sum of their values is 88 . If he chooses the number 1002100_{2} , then a=1012,b=0112,c=1112a=101_{2},b=011_{2},c=111_{2} , the sum of their values is 1515 .

For the second test, the minimum and maximum sum of variables aa , bbbb , cxcx , dd and ee is 2, and this sum doesn't depend on the number chosen by Peter, so the minimum Peter can choose is 00 .

输入输出样例

  • 输入#1

    3 3
    a := 101
    b := 011
    c := ? XOR b
    

    输出#1

    011
    100
    
  • 输入#2

    5 1
    a := 1
    bb := 0
    cx := ? OR a
    d := ? XOR ?
    e := d AND bb
    

    输出#2

    0
    0
    

说明/提示

In the first sample if Peter chooses a number 0112011_{2} , then a=1012,b=0112,c=0002a=101_{2},b=011_{2},c=000_{2} , the sum of their values is 88 . If he chooses the number 1002100_{2} , then a=1012,b=0112,c=1112a=101_{2},b=011_{2},c=111_{2} , the sum of their values is 1515 .

For the second test, the minimum and maximum sum of variables aa , bbbb , cxcx , dd and ee is 2, and this sum doesn't depend on the number chosen by Peter, so the minimum Peter can choose is 00 .

首页