53292023-04-25 22:27:30rmlanZárójelekcpp14Accepted 100/10025ms6820 KiB
#include<bits/stdc++.h>
using namespace std;

struct z{
    int b=0,r=0,id;
};
bool comp(z a, z b){
    return a.r < b.r;
}
bool comp2(z a, z b){
    return a.r+a.b > b.r+b.b;
}

int main(){
    int n;
    cin >> n;
    vector<z> pos,neg;
    for(int i = 1; i <= n; i++){
        string s;
        cin >> s;
        z c;
        c.id = i;
        for(int j = 0; j < s.length(); j++){
            if(s[j]=='('){
                c.b++;
            }else{
                c.b--;
            }
            c.r = min(c.r, c.b);
        }
        c.r = abs(c.r);
        if(c.b >= 0){
            pos.push_back(c);
        }else{
            neg.push_back(c);
        }

    }
    sort(pos.begin(), pos.end(), comp);
    sort(neg.begin(), neg.end(), comp2);
    int b=0;
    vector<int> ans;
    for(z i:pos){
        if(i.r > b){
            cout << -1;
            return 0;
        }
        ans.push_back(i.id);
        b+=i.b;
    }
    for(z i:neg){
        /*if(i.r > b || b < 0){
            cout << -1;
            return 0;
        }*/
        ans.push_back(i.id);
        b+=i.b;
    }
    if(b != 0){
        cout << "-1";
        return 0;

    }
    for(int i:ans){
        cout << i << " ";
    }

}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1808 KiB
2Accepted8ms2180 KiB
subtask211/11
3Accepted3ms2328 KiB
4Accepted3ms2540 KiB
5Accepted3ms2672 KiB
6Accepted3ms2728 KiB
7Accepted7ms3228 KiB
8Accepted7ms3448 KiB
subtask36/6
9Accepted8ms3188 KiB
10Accepted8ms3520 KiB
11Accepted8ms3472 KiB
subtask414/14
12Accepted8ms3672 KiB
13Accepted8ms3720 KiB
subtask523/23
14Accepted8ms3628 KiB
15Accepted8ms3936 KiB
subtask619/19
16Accepted7ms4020 KiB
17Accepted8ms4076 KiB
18Accepted8ms4156 KiB
19Accepted8ms4368 KiB
20Accepted8ms4328 KiB
21Accepted6ms4436 KiB
22Accepted6ms4368 KiB
23Accepted6ms4644 KiB
24Accepted6ms4580 KiB
subtask727/27
25Accepted7ms4516 KiB
26Accepted8ms4668 KiB
27Accepted8ms4676 KiB
28Accepted8ms4684 KiB
29Accepted10ms5052 KiB
30Accepted25ms6820 KiB
31Accepted8ms4832 KiB
32Accepted8ms4988 KiB
33Accepted8ms4676 KiB
34Accepted9ms4844 KiB
35Accepted8ms4752 KiB
36Accepted9ms5088 KiB
37Accepted7ms4856 KiB
38Accepted8ms4864 KiB
39Accepted14ms5748 KiB
40Accepted4ms4800 KiB
41Accepted4ms4748 KiB
42Accepted7ms4992 KiB
43Accepted6ms4976 KiB