포럼
문제 COCI00465

Retro

설명

Little Mirko got a video game console for Christmas. It wasn’t a Playstation 4 or an Xbox
one, but Atari 2600, and it came with one free game. The protagonist of the game is
standing on the bottom of the screen, and there are various objects dispersed on the rest of
the screen, falling towards the bottom.
More precisely, the screen can be represented as a grid of RxS pixels arranged in \(R\) rows
and \(S\) columns. The protagonist takes up one pixel of the lowest line and is marked with ‘M’.
The rest of the pixels are marked with some of the characters: ‘.’ (empty space), ‘*’ (bomb),
‘(‘ (open bracket) or ‘)’ (closed bracket).
The protagonist can move one pixel to the left or to the right in a single move, but doesn’t
need to, whereas the rest of the objects simultaneously move one pixel down (possibly out
of the screen). When the protagonist finds himself at the same position as one of the
brackets, we say that he picked up that bracket and added it at the end of his array of
acquired brackets. The protagonist’s goal is to acquire the longest possible valid bracket
expression.
A valid bracket expression is defined inductively in the following way:

“()” is a valid expression

If a is a valid expression, then “(a)” is a valid expression as well

If a and b are valid expressions, then “ab” is a valid expression as well
The game ends when the protagonist finds himself at the same position as the bomb, or
when all the objects fall out of the screen.

제약

In test cases worth 25% of total points, it will hold \(1 \le R \le 15\).
In test cases worth 50% of total points, it will hold \(1 \le R \le 100\).
If you output the correct length, but the wrong expression, you will be awarded 40% of points
for that test case. In any case, in order to score points, your output must consist of two
non-empty lines.

입력 형식

The first line of input contains the positive integers \(R\) and \(S\) (\(1 \le R\), \(S \le 300\)) that represent
the dimensions of the screen.
Each of the following \(R\) lines contains \(S\) characters ‘M’, ‘.’, ‘*’, ‘(‘ or ‘)’ that represent the initial
state of the screen.
Test data will be such that there will always exist at least one valid bracket expression that is
possible to acquire.

출력 형식

In the first line, you must output the length of the longest valid bracket expression that Mirko
can acquire.
In the second line, output that expression. If there are multiple longest valid expressions,
output the lexicographically smallest one.

예제 1
입력
5 4
..).
.)(.
(.)*
*(.*
..M.
출력
4
(())
예제 2
입력
6 3
)(.
*..
(**
)()
().
M..
출력
4
()()
예제 3
입력
6 3
((.
*..
(**
)()
().
M..
출력
2
()
문제 정보

생성자가 기록되지 않았습니다.

출처 COCI 2017/2018 Contest 3

평가 및 의견

Retro

개요
출제자 난이도 Unrated 레이팅 미적용 의견 0 / 1 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

Retro

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8