欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1703C.Cypher
Cypher
Luca has a cypher made up of a sequence of wheels, each with a digit written on it. On the -th wheel, he made moves. Each move is one of two types:
- up move (denoted by
U): it increases the -th digit by . After applying the up move on , it becomes . - down move (denoted by
D): it decreases the -th digit by . After applying the down move on , it becomes .
Example for . The current sequence is 0 0 0 0.
Luca knows the final sequence of wheels and the moves for each wheel. Help him find the original sequence and crack the cypher.
Input
The first line contains a single integer () — the number of test cases.
The first line of each test case contains a single integer () — the number of wheels.
The second line contains integers () — the digit shown on the -th wheel after all moves have been performed.
Then lines follow, the -th of which contains the integer () and characters that are either U or D — the number of moves performed on the -th wheel, and the moves performed. U and D represent an up move and a down move respectively.
Output
For each test case, output space-separated digits — the initial sequence of the cypher.
Note
In the first test case, we can prove that initial sequence was . In that case, the following moves were performed:
- On the first wheel: $2 \xrightarrow[\texttt{D}]{} 1 \xrightarrow[\texttt{D}]{} 0 \xrightarrow[\texttt{D}]{} 9$.
- On the second wheel: $1 \xrightarrow[\texttt{U}]{} 2 \xrightarrow[\texttt{D}]{} 1 \xrightarrow[\texttt{U}]{} 2 \xrightarrow[\texttt{U}]{} 3$.
- On the third wheel: $1 \xrightarrow[\texttt{D}]{} 0 \xrightarrow[\texttt{U}]{} 1$.
The final sequence was , which matches the input.
Samples
3
3
9 3 1
3 DDD
4 UDUU
2 DU
2
0 9
9 DDDDDDDDD
9 UUUUUUUUU
5
0 5 9 8 3
10 UUUUUUUUUU
3 UUD
8 UUDUUDDD
10 UUDUUDUDDU
4 UUUU
2 1 1
9 0
0 4 9 6 9
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |