CF1101B.Accordion
普及-
通过率:0%
时间限制:3.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
An accordion is a string (yes, in the real world accordions are musical instruments, but let's forget about it for a while) which can be represented as a concatenation of: an opening bracket (ASCII code 091), a colon (ASCII code 058), some (possibly zero) vertical line characters (ASCII code 124), another colon, and a closing bracket (ASCII code 093). The length of the accordion is the number of characters in it.
For example, [::], [:||:] and [:|||:] are accordions having length 4, 6 and 7. (:|:), {:||:}, [:], ]:||:[ are not accordions.
You are given a string s. You want to transform it into an accordion by removing some (possibly zero) characters from it. Note that you may not insert new characters or reorder existing ones. Is it possible to obtain an accordion by removing characters from s, and if so, what is the maximum possible length of the result?
手风琴(accordion)是一个字符串(是的,在现实世界中手风琴是一种乐器,但让我们暂时忽略这一点),它可以表示为以下几部分的拼接:一个左方括号(ASCII 码 091)、一个冒号(ASCII 码 058)、若干(可能为零个)竖线字符(ASCII 码 124)、另一个冒号、以及一个右方括号(ASCII 码 093)。手风琴的长度即为其所含字符的个数。
例如,[::]、[:∣∣:] 和 [:∣∣∣:] 是长度分别为 4、6 和 7 的手风琴。而 (:∣:)、{:∣∣:}、[:\]、]∣∣:[ 不是手风琴。
给定一个字符串 s。你希望通过从其中删除若干(可能为零个)字符,将其转化为一个手风琴。注意:你不能插入新字符,也不能重排已有字符。问:是否可能通过删除字符的方式从 s 得到一个手风琴?如果可以,所能得到的手风琴的最大长度是多少?
输入格式
The only line contains one string s (1≤∣s∣≤500000). It consists of lowercase Latin letters and characters [, ], : and |.
仅有一行,包含一个字符串 s(1≤∣s∣≤500000)。该字符串由小写拉丁字母以及字符 [, ], : 和 | 组成。
输出格式
If it is not possible to obtain an accordion by removing some characters from s, print −1. Otherwise print maximum possible length of the resulting accordion.
如果无法通过从字符串 s 中删除某些字符来得到手风琴字符串,则输出 −1;否则输出所得手风琴字符串的最大可能长度。
输入输出样例
输入#1
|[a:b:|]
输出#1
4
输入#2
|]:[|:]
输出#2
-1
输入解题思路,AI测评打分。不知道怎么写?