ENG  RUSTimus Online Judge
Online Judge
Задачи
Авторы
Соревнования
О системе
Часто задаваемые вопросы
Новости сайта
Форум
Ссылки
Архив задач
Отправить на проверку
Состояние проверки
Руководство
Регистрация
Исправить данные
Рейтинг авторов
Текущее соревнование
Расписание
Прошедшие соревнования
Правила
вернуться в форум

Обсуждение задачи 1574. Математики и скобки

O(n)
Послано jagatsastry 24 ноя 2007 13:29
I used an O(n*n) method and got TLE#9. Does anyone know of any O(n) method. I actually checked every cyclic shift to see if it is a valid expression.
Re: O(n)
Послано Victor Barinov (TNU) 24 ноя 2007 20:36
Of course there are exists O(n) algo. You just must to find 1 valid cyclic shift. And then check balance in it. Number of points with balance == 0 will be the answer to ploblem.
Re: O(n)
Послано Denis Koshman 16 июл 2008 21:00
There is another method - check number of points where minimal disballance is nonnegative (after checking that overall ballance is zero).
Re: O(n)
Послано Oleg Strekalovsky [Vologda SPU] 21 апр 2009 14:00
I think,that your algo get TLE on new tests.
Because, it's not diffucult crate test,where your program will do o(N^2).
Exampel - 49999 times '(', 50000 times ')', 1 time ')'.

My AC program find shift, not finding right bracket expression (it's O(N^2)), but by an other method ( n steps).

Good luck =)

Edited by author 21.04.2009 21:12
Re: O(n)
Послано Zayakin Andrey[PermSU] 21 авг 2010 01:33
There is exist  O(n*log(n)) solution.
Re: O(n)
Послано Nic Roets 11 ноя 2011 14:41
If the sequence s is of length n, consider the sequence ss, which will have length 2n. Now define l_i as the number of '(' in the first i characters of ss and r_i as the number of ')' in the first i characters of ss. Let d_i=l_i-r_i. We want to know if there are any  numbers smaller than d_i in d_i, ... , d_{n+i}. Interval trees will give you O(n log n) algorithm, but there are even simpler algorithms that will give you an O(n) algorithm (Hint: d_i is continuous).
Re: O(n)
Послано arrammis 28 май 2018 18:30
What do you mean when saying "point" ?? What is "point" here ? Could you please give a clear description of this method ?