Logo
(追記) (追記ここまで)

25671번 - Bracket-and-bar Sequences 다국어투 스텝

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 (추가 시간 없음) 1024 MB105375.000%

문제

Let us define the set of regular bracket-and-bar sequences $R$ recursively. It is the set of strings that can be obtained following only the rules below:

  • $\varepsilon \in R$ (empty string)
  • $A, B \in R \Rightarrow AB \in R$ (concatenation)
  • $A, B \in R \Rightarrow $($A$|$B$)$ \in R$

For example, the sequences containing two triples "(|)" look as folows: "((|)|)", "(|(|))", "(|)(|)".

Establish a correspondence between regular bracket-and-bar sequences of certain length and integers, and implement that correspondence.

입력

출력

제한

인터랙션

In this problem, your solution will be run twice on each test. Each line of input is terminated by an end-of-line character.

첫 번째 실행

During the first run, the solution encodes bracket-and-bar sequences as integers. The first line contains the word "encode". The second line contains an integer $t$: the number of test cases (1ドル \le t \le 1000$). Each test case is given on two lines: the first line contains an integer $n$ which is the number of "(|)" triples in the sequence (1ドル \le n \le 25$), and the second line contains 3ドル n$ characters without spaces, constituting a reqular bracket-and-bar sequence with $n$ triples.

Print $t$ lines, one for each test case. On the $i$-th line, print an integer $x_i$ which you chose to encode the $i$-th sequence from the input (0ドル \le x_i \le 2 \cdot 10^{18}$).

두 번째 실행

During the second run, the solution decodes bracket-and-bar sequences from integers. The first line contains the word "decode". The second line contains an integer $t$: the number of test cases (1ドル \le t \le 1000$). Each test case is given on two lines: the first line contains an integer $n$ which is the number of "(|)" triples in the sequence (1ドル \le n \le 25$), and the second line contains the integer printed by your solution for this test case during the first run.

Print $t$ lines, one for each test case. On the $i$-th line, print the bracket-and-bar sequence from the $i$-th test case.

예제

For each test, the input during the second run depends on the solution's output during the first run.

Below we show two runs of a certain solution on the first test. It can be seen that this solution encodes the characters by digits 1ドル,ドル 2ドル,ドル and 3ドル,ドル and just prints the resulting string of digits as the encoding integer. Unfortunately, for large $n,ドル the strings will become too long.

예제 입력 1

encode
3
1
(|)
4
((((|)|)|)|)
5
(|(|))((|(|))|)

예제 출력 1

123
111123232323
121233112123323

예제 입력 2

decode
3
1
123
4
111123232323
5
121233112123323

예제 출력 2

(|)
((((|)|)|)|)
(|(|))((|(|))|)

힌트

출처

Camp > Petrozavodsk Programming Camp > Summer 2022 > Day 4: Ivan Kazmenko Contest 3 A번

채점 및 기타 정보

  • 예제는 채점하지 않는다.
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /