A10783 | Bitwise Formula
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
The first line contains two integers $n$ and $m$ , the number of variables and bit depth, respectively ( $1<=n<=5000$ ; $1<=m<=1000$ ).
The following $n$ 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 $m$ 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.
The following $n$ 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 $m$ 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 $m$ -bit binary numbers.
输出格式
In the first sample if Peter chooses a number $011_{2}$ , then $a=101_{2},b=011_{2},c=000_{2}$ , the sum of their values is $8$ . If he chooses the number $100_{2}$ , then $a=101_{2},b=011_{2},c=111_{2}$ , the sum of their values is $15$ .
For the second test, the minimum and maximum sum of variables $a$ , $bb$ , $cx$ , $d$ and $e$ is 2, and this sum doesn't depend on the number chosen by Peter, so the minimum Peter can choose is $0$ .
For the second test, the minimum and maximum sum of variables $a$ , $bb$ , $cx$ , $d$ and $e$ is 2, and this sum doesn't depend on the number chosen by Peter, so the minimum Peter can choose is $0$ .
输入输出样例
输入 #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 $011_{2}$ , then $a=101_{2},b=011_{2},c=000_{2}$ , the sum of their values is $8$ . If he chooses the number $100_{2}$ , then $a=101_{2},b=011_{2},c=111_{2}$ , the sum of their values is $15$ .
For the second test, the minimum and maximum sum of variables $a$ , $bb$ , $cx$ , $d$ and $e$ is 2, and this sum doesn't depend on the number chosen by Peter, so the minimum Peter can choose is $0$ .
For the second test, the minimum and maximum sum of variables $a$ , $bb$ , $cx$ , $d$ and $e$ is 2, and this sum doesn't depend on the number chosen by Peter, so the minimum Peter can choose is $0$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted