A12659 | Optimizer
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Let's analyze a program written on some strange programming language. The variables in this language have names consisting of $1$ to $4$ characters, and each character is a lowercase or an uppercase Latin letter, or a digit. There is an extra constraint that the first character should not be a digit.
There are four types of operations in the program, each denoted by one of the characters: $, ^, \# or &.
Each line of the program has one of the following formats:
- <lvalue>=<rvalue>, where <lvalue> and <rvalue> are valid variable names;
- <lvalue>=<arg1><op><arg2>, where <lvalue>, <arg1> and <arg2> are valid variable names, and <op> is an operation character.
The program is executed line-by-line, and the result of execution is stored in a variable having the name res. If res is never assigned in the program, then the result will be equal to the value of res before running the program.
Two programs are called equivalent if no matter which operations do characters$, ^, \# and & denote (but, obviously, performing the same operation on the same arguments gives the same result) and which values do variables have before execution of program, the value of res after running the first program is equal to the value of res after running the second program (the programs are executed independently).
You are given a program consisting of $n$ lines. Your task is to write a program consisting of minimum possible number of lines that is equivalent to the program you are given.
There are four types of operations in the program, each denoted by one of the characters: $, ^, \# or &.
Each line of the program has one of the following formats:
- <lvalue>=<rvalue>, where <lvalue> and <rvalue> are valid variable names;
- <lvalue>=<arg1><op><arg2>, where <lvalue>, <arg1> and <arg2> are valid variable names, and <op> is an operation character.
The program is executed line-by-line, and the result of execution is stored in a variable having the name res. If res is never assigned in the program, then the result will be equal to the value of res before running the program.
Two programs are called equivalent if no matter which operations do characters$, ^, \# and & denote (but, obviously, performing the same operation on the same arguments gives the same result) and which values do variables have before execution of program, the value of res after running the first program is equal to the value of res after running the second program (the programs are executed independently).
You are given a program consisting of $n$ lines. Your task is to write a program consisting of minimum possible number of lines that is equivalent to the program you are given.
输入格式
The first line contains one integer $n$ ( $1 \le n \le 1000$ ) — the number of lines in the program.
Then $n$ lines follow — the program itself. Each line corresponds to the format described in the statement and has no extra whitespaces.
Then $n$ lines follow — the program itself. Each line corresponds to the format described in the statement and has no extra whitespaces.
输出格式
In the first line print $k$ — the minimum number of lines in the equivalent program.
Then print $k$ lines without any whitespaces — an equivalent program having exactly $k$ lines, in the same format it is described in the statement.
Then print $k$ lines without any whitespaces — an equivalent program having exactly $k$ lines, in the same format it is described in the statement.
输入输出样例
输入 #1
4 c=aa#bb d12=c res=c^d12 tmp=aa$c
输出 #1
2 aaaa=aa#bb res=aaaa^aaaa
输入 #2
2 max=aaaa$bbbb min=bbbb^aaaa
输出 #2
0
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted