53192023-04-25 21:32:01rmlanZárójelekcpp14Wrong answer 43/10024ms6600 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
2Accepted8ms2240 KiB
subtask20/11
3Accepted3ms2224 KiB
4Wrong answer3ms2464 KiB
5Accepted3ms2680 KiB
6Accepted3ms2888 KiB
7Accepted7ms3452 KiB
8Accepted7ms3416 KiB
subtask36/6
9Accepted8ms3196 KiB
10Accepted8ms3196 KiB
11Accepted8ms3456 KiB
subtask414/14
12Accepted8ms3424 KiB
13Accepted8ms3412 KiB
subtask523/23
14Accepted8ms3552 KiB
15Accepted8ms3604 KiB
subtask60/19
16Accepted7ms3600 KiB
17Accepted8ms3608 KiB
18Accepted8ms3972 KiB
19Accepted8ms3912 KiB
20Accepted8ms4168 KiB
21Wrong answer6ms4120 KiB
22Wrong answer6ms4380 KiB
23Wrong answer6ms4580 KiB
24Wrong answer6ms4544 KiB
subtask70/27
25Accepted7ms4480 KiB
26Accepted8ms4484 KiB
27Accepted8ms4584 KiB
28Accepted8ms4596 KiB
29Accepted10ms4944 KiB
30Accepted24ms6600 KiB
31Accepted8ms4548 KiB
32Accepted8ms4708 KiB
33Accepted8ms4516 KiB
34Accepted9ms4684 KiB
35Accepted8ms4468 KiB
36Accepted9ms4724 KiB
37Accepted7ms4600 KiB
38Accepted8ms4620 KiB
39Accepted14ms5576 KiB
40Wrong answer6ms4764 KiB
41Wrong answer4ms4812 KiB
42Wrong answer7ms4892 KiB
43Wrong answer7ms4768 KiB