CF1703C.Cypher

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

Luca has a cypher made up of a sequence of nn wheels, each with a digit aia_i written on it. On the ii -th wheel, he made bib_i moves. Each move is one of two types:

  • up move (denoted by U\texttt{U} ): it increases the ii -th digit by 11 . After applying the up move on 99 , it becomes 00 .
  • down move (denoted by D\texttt{D} ): it decreases the ii -th digit by 11 . After applying the down move on 00 , it becomes 99 .

Example for n=4n=4 . 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.

输入格式

The first line contains a single integer tt ( 1t1001 \leq t \leq 100 ) — the number of test cases.

The first line of each test case contains a single integer nn ( 1n1001 \leq n \leq 100 ) — the number of wheels.

The second line contains nn integers aia_i ( 0ai90 \leq a_i \leq 9 ) — the digit shown on the ii -th wheel after all moves have been performed.

Then nn lines follow, the ii -th of which contains the integer bib_i ( 1bi101 \leq b_i \leq 10 ) and bib_i characters that are either U\texttt{U} or D\texttt{D} — the number of moves performed on the ii -th wheel, and the moves performed. U\texttt{U} and D\texttt{D} represent an up move and a down move respectively.

输出格式

For each test case, output nn space-separated digits — the initial sequence of the cypher.

输入输出样例

  • 输入#1

    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

    输出#1

    2 1 1 
    9 0 
    0 4 9 6 9

说明/提示

In the first test case, we can prove that initial sequence was [2,1,1][2,1,1] . In that case, the following moves were performed:

  • On the first wheel: 2D1D0D92 \xrightarrow[\texttt{D}]{} 1 \xrightarrow[\texttt{D}]{} 0 \xrightarrow[\texttt{D}]{} 9 .
  • On the second wheel: 1U2D1U2U31 \xrightarrow[\texttt{U}]{} 2 \xrightarrow[\texttt{D}]{} 1 \xrightarrow[\texttt{U}]{} 2 \xrightarrow[\texttt{U}]{} 3 .
  • On the third wheel: 1D0U11 \xrightarrow[\texttt{D}]{} 0 \xrightarrow[\texttt{U}]{} 1 .

The final sequence was [9,3,1][9,3,1] , which matches the input.

首页