53182023-04-25 21:30:52rmlanZárójelekcpp14Wrong answer 43/10025ms6892 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
2Accepted8ms2236 KiB
subtask20/11
3Accepted3ms2384 KiB
4Wrong answer3ms2552 KiB
5Accepted3ms2656 KiB
6Accepted3ms2860 KiB
7Accepted7ms3324 KiB
8Accepted8ms3552 KiB
subtask36/6
9Accepted8ms3556 KiB
10Accepted8ms3704 KiB
11Accepted8ms3788 KiB
subtask414/14
12Accepted8ms3768 KiB
13Accepted8ms3668 KiB
subtask523/23
14Accepted8ms3744 KiB
15Accepted8ms3736 KiB
subtask60/19
16Accepted8ms3648 KiB
17Accepted8ms3840 KiB
18Accepted8ms4200 KiB
19Accepted8ms4528 KiB
20Accepted8ms4364 KiB
21Wrong answer6ms4664 KiB
22Wrong answer6ms4620 KiB
23Wrong answer6ms4616 KiB
24Wrong answer6ms4620 KiB
subtask70/27
25Accepted8ms4560 KiB
26Accepted8ms4668 KiB
27Accepted8ms4780 KiB
28Accepted8ms4780 KiB
29Accepted12ms4968 KiB
30Accepted25ms6892 KiB
31Accepted8ms4944 KiB
32Accepted9ms5012 KiB
33Accepted8ms4824 KiB
34Accepted9ms4996 KiB
35Accepted8ms4872 KiB
36Accepted9ms5036 KiB
37Accepted8ms4784 KiB
38Accepted8ms4796 KiB
39Accepted14ms5676 KiB
40Wrong answer4ms4816 KiB
41Wrong answer4ms4944 KiB
42Wrong answer7ms5252 KiB
43Wrong answer6ms5188 KiB