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

Обсуждение задачи 1745. Ещё Один Ответ

One of the correct sorting function
Послано vectorlmn 31 мар 2025 12:30
Becuase of edge cases,this problem take me many hours.
So I put one correct sorting function here.
struct ND{// Single bracket sequence
    int len,mn=0;
    int cnt=0;
    int id;
// len is the length of the bracket sequence
// if we define '(' as +1,and ')' as -1,the minimum prefix sum of the bracket sequence is mn.
// and the total sum of the sequence is cnt
// id is the index of the bracket sequence in the given input.
}nd[maxn];
bool swap(ND& a,ND& b){
        if(a.cnt>=0&&b.cnt<0)return 1;// a first
        if(a.cnt<0&&b.cnt>=0)return 0;// b first
        if(a.cnt>=0)return -a.mn<-b.mn;
        return -b.mn+b.cnt<-a.mn+a.cnt;
}