ГлавнаяСборникиТурнирыРазделыФорумыУчастникиПечатьПомощьО системе

Сборники > Kovrov IT > задача:


2008.C. 50262 - Brackets

Гость
• Обсуждение задачи (4)

Задачи сборника

• 2007.F. 50690 - Parliament
• 2007.G. 50272 - Strange Numbers
• 2007.H. 50273 - Two Captains
• 2007.I. 50274 - Boundary Troops
• 2007.J. 50275 - Wedding
• 2007.K. 50276 - Nice Floor
• 2008.A. 50672 - Math and Soldiers
• 2008.B. 50261 - Roads
• 2008.C. 50262 - Brackets
• 2008.D. 50279 - Bit Decoder
• 2008.E. 50263 - Points
• 2008.F. 50972 - Division
• 2008.G. 50264 - String Multiplication
• 2008.H. 50254 - Lawyers Council
• 2009.A. 50283 - Tetris 3D
• 2009.B. 50284 - Knights of the Rook
• 2009.C. 50285 - Meat store

Обратная связь

Если у вас есть предложения или пожелания по работе Contester, посетите форум сайта www.contester.ru.

Лимит времени 2000/4000/4000/4000 мс. Лимит памяти 65000/65000/65000/65000 Кб.
Автор: Павел Кузнецов, ПГУ.

Correct bracket expression (CBE below) can be defined in the following way:

1. () - CBE
2. If A is CBE, then (A) is also CBE
3. If both A and B are CBE, then AB is also CBE

For example, (()()) is CBE, while ())( is not.

One can see from the above, that each opening bracket has a corresponding closing bracket. A pair from the opening bracket and corresponding closing bracket shallbe called block. You are given a correct bracket expression. Your task is to find the number of different block pairs, such that one block lies inside another.

Input
The first row of input file contains CBE. It's length does not exceed one million of symbols.
Output
Output one number - the amount of block pairs in the given CBE, such that one block lies inside another.

Input 1 Output 1 Input 2 Output 2 Input 3 Output 3 Input 4 Output 4
()()()
0
()(())
1
(()())
2
((()))
3

Для отправки решений необходимо выполнить вход.

www.contester.ru