Problem - E - Codeforces
Problem - E - Codeforces
alfa_flex
| Logout
HOME TOP CATALOG CONTESTS GYM PROBLEMSET GROUPS RATING EDU API CALENDAR HELP
Mashup
E. Pair Matching Contest is running
time limit per test: 2 s.
04:56:55
memory limit per test: 256 MB
input: standard input Contestant
output: standard output
You have an array consisting of n bracket sequences. You pick a pair of bracket sequences. A
pair is called good if you concatenate elements of this pair and they form a regular bracket → Submit?
sequence. You want to find out what is the maximum number of good pairs you can make
such that each bracket sequence occurs in at most one pair.
Language: GNU G++17 7.3.0
A regular bracket sequence is a bracket sequence that can be transformed into a correct
Choose
arithmetic expression by inserting characters "1" and "+" between the original characters of the Choose File No file chosen
file:
sequence
Submit
Input
The first line contains one integer n (1 ≤ n ≤ 10
5
) — the number of bracket sequences.
Each of the following n lines contains one bracket sequence — a non-empty string that
consists only of characters "(" and ")".
Note that a bracket sequence may appear in the input multiple times. In this case, you can use
each copy of the sequence separately. Also, note that the order in which strings appear in the
input doesn't matter.
Output
Print a single integer — the maximum number of pairs that can be made, adhering to the
conditions in the statement.
Examples
input Copy
)())
((
((
output Copy
input Copy
((
(((
(())
output Copy
input Copy
(())
()
output Copy
https://codeforces.com/gym/382540/problem/E 1/2
5/21/22, 7:03 PM Problem - E - Codeforces
Supported by
https://codeforces.com/gym/382540/problem/E 2/2