53102023-04-25 19:20:39rmlanZárójelekcpp14Wrong answer 43/10024ms6396 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(), 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
1Accepted3ms1812 KiB
2Accepted8ms2232 KiB
subtask20/11
3Accepted3ms2380 KiB
4Wrong answer3ms2544 KiB
5Accepted3ms2752 KiB
6Accepted3ms2848 KiB
7Accepted8ms3440 KiB
8Accepted8ms3400 KiB
subtask36/6
9Accepted8ms3224 KiB
10Accepted8ms3220 KiB
11Accepted8ms3268 KiB
subtask414/14
12Accepted8ms3544 KiB
13Accepted8ms3760 KiB
subtask523/23
14Accepted8ms3756 KiB
15Accepted8ms4072 KiB
subtask60/19
16Accepted7ms4004 KiB
17Accepted8ms4012 KiB
18Accepted8ms4028 KiB
19Accepted8ms4240 KiB
20Accepted8ms4236 KiB
21Wrong answer6ms4236 KiB
22Wrong answer6ms4508 KiB
23Wrong answer6ms4464 KiB
24Wrong answer6ms4416 KiB
subtask70/27
25Accepted7ms4324 KiB
26Accepted8ms4364 KiB
27Accepted8ms4400 KiB
28Accepted8ms4416 KiB
29Accepted10ms4728 KiB
30Accepted24ms6396 KiB
31Accepted8ms4404 KiB
32Accepted9ms4564 KiB
33Accepted8ms4384 KiB
34Accepted9ms4576 KiB
35Accepted8ms4352 KiB
36Accepted10ms4828 KiB
37Accepted8ms4796 KiB
38Accepted8ms5016 KiB
39Accepted14ms5872 KiB
40Wrong answer4ms5016 KiB
41Wrong answer3ms4996 KiB
42Wrong answer7ms5196 KiB
43Wrong answer6ms5024 KiB