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

7695번 - Brackets 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 128 MB49292472.727%

문제

We give the following inductive definition of a “regular brackets” sequence:

  • the empty sequence is a regular brackets sequence,
  • if s is a regular brackets sequence, then (s) and [s] are regular brackets sequences, and
  • if a and b are regular brackets sequences, then ab is a regular brackets sequence.
  • no other sequence is a regular brackets sequence

For instance, all of the following character sequences are regular brackets sequences:

(), [], (()), ()[], ()[()]

while the following character sequences are not:

(, ], )(, ([)], ([(]

Given a brackets sequence of characters a1a2...an, your goal is to find the length of the longest regular brackets sequence that is a subsequence of s. That is, you wish to find the largest m such that for indices i1, i2, . . . , im where 1 ≤ i1 < i2 < . . . < im ≤ n, ai1 ai2 . . . aim is a regular brackets sequence.

입력

The input test file will contain multiple test cases. Each input test case consists of a single line containing only the characters (, ), [, and ]; each input test will have length between 1 and 100, inclusive. The end-of-file is marked by a line containing the word “end” and should not be processed.

출력

For each input case, the program should print the length of the longest possible regular brackets subsequence on a single line.

제한

예제 입력 1

((()))
()()()
([]])
)[)(
([][][)
end

예제 출력 1

6
6
4
0
6

힌트

Given the initial sequence ([([]])], the longest regular brackets subsequence is [([])].

출처

University > Stanford Local ACM Programming Contest > SLPC 2004 5번

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

출처

대학교 대회

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

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