53122023-04-25 19:43:22rmlanZárójelekcpp14Wrong answer 20/10017ms7012 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 > b.r;
}

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(), comp);
    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
subtask20/11
3Accepted3ms2332 KiB
4Wrong answer3ms2580 KiB
5Wrong answer3ms2676 KiB
6Accepted2ms2724 KiB
7Accepted8ms3348 KiB
8Accepted8ms3556 KiB
subtask36/6
9Accepted8ms3560 KiB
10Accepted8ms3776 KiB
11Accepted8ms3876 KiB
subtask414/14
12Accepted8ms3740 KiB
13Accepted8ms3732 KiB
subtask50/23
14Wrong answer8ms3812 KiB
15Wrong answer8ms3700 KiB
subtask60/19
16Wrong answer8ms3808 KiB
17Wrong answer8ms4024 KiB
18Accepted8ms4376 KiB
19Wrong answer8ms4268 KiB
20Wrong answer8ms4532 KiB
21Wrong answer6ms4640 KiB
22Wrong answer6ms4512 KiB
23Wrong answer6ms4512 KiB
24Wrong answer6ms4512 KiB
subtask70/27
25Accepted8ms4588 KiB
26Wrong answer8ms4576 KiB
27Wrong answer8ms4612 KiB
28Wrong answer8ms4624 KiB
29Wrong answer9ms4968 KiB
30Wrong answer17ms7012 KiB
31Wrong answer8ms4968 KiB
32Wrong answer8ms5008 KiB
33Wrong answer8ms4932 KiB
34Wrong answer8ms5092 KiB
35Wrong answer8ms4968 KiB
36Wrong answer9ms5128 KiB
37Accepted8ms4864 KiB
38Wrong answer8ms4880 KiB
39Wrong answer12ms5676 KiB
40Wrong answer4ms4812 KiB
41Wrong answer4ms4760 KiB
42Wrong answer7ms4988 KiB
43Wrong answer6ms4828 KiB