53732023-04-26 19:34:29gortomiZárójelekcpp17Accepted 100/10019ms9376 KiB
#include <bits/stdc++.h>
using namespace std;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    vector<string> s(n);
    for(int i = 0; i < n; i++) cin >> s[i];
    vector<pair<int, int> > v1, v2;
    vector<int> t(n);
    int sum = 0;
    for(int i = 0; i < n; i++)
    {
        int act = 0, mini = 0;
        for(auto x : s[i])
        {
            if(x == '(') act++;
            else act--;
            mini = min(mini, act);
        }
        mini *= -1;
        if(act > 0)
        {
            v1.push_back({mini, i});
            t[i] = act;
        }
        else
        {
            v2.push_back({mini + act, i});
            t[i] = -act;
        }
        sum += act;
    }
    if(sum != 0)
    {
        cout << "-1";
        return 0;
    }
    int cur = 0;
    vector<int> ans1, ans2;
    sort(v1.begin(), v1.end());
    sort(v2.begin(), v2.end());
    for(auto x : v1)
    {
        if(x.first > cur)
        {
            cout << "-1";
            return 0;
        }
        int y = x.second;
        ans1.push_back(y);
        cur += t[y];
    }
    cur = 0;
    for(auto x : v2)
    {
        if(x.first > cur)
        {
            cout << "-1";
            return 0;
        }
        int y = x.second;
        ans2.push_back(y);
        cur += t[y];
    }
    for(auto x : ans1) cout << x + 1 << " ";
    reverse(ans2.begin(), ans2.end());
    for(auto x : ans2) cout << x + 1 << " ";
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1832 KiB
2Accepted4ms2748 KiB
subtask211/11
3Accepted3ms2232 KiB
4Accepted3ms2572 KiB
5Accepted3ms2532 KiB
6Accepted3ms2768 KiB
7Accepted3ms3448 KiB
8Accepted3ms3552 KiB
subtask36/6
9Accepted4ms3784 KiB
10Accepted4ms3960 KiB
11Accepted4ms3996 KiB
subtask414/14
12Accepted4ms4276 KiB
13Accepted4ms4112 KiB
subtask523/23
14Accepted4ms4412 KiB
15Accepted4ms4496 KiB
subtask619/19
16Accepted3ms4388 KiB
17Accepted4ms4432 KiB
18Accepted4ms4500 KiB
19Accepted4ms4468 KiB
20Accepted4ms4468 KiB
21Accepted4ms4428 KiB
22Accepted4ms4424 KiB
23Accepted4ms4712 KiB
24Accepted4ms4640 KiB
subtask727/27
25Accepted3ms4540 KiB
26Accepted4ms4916 KiB
27Accepted4ms4972 KiB
28Accepted4ms5180 KiB
29Accepted7ms5692 KiB
30Accepted19ms9376 KiB
31Accepted4ms5404 KiB
32Accepted4ms5424 KiB
33Accepted4ms5440 KiB
34Accepted4ms5668 KiB
35Accepted4ms5404 KiB
36Accepted6ms6048 KiB
37Accepted4ms5428 KiB
38Accepted4ms5744 KiB
39Accepted9ms7612 KiB
40Accepted4ms5604 KiB
41Accepted3ms5100 KiB
42Accepted4ms5620 KiB
43Accepted4ms5704 KiB