167752025-05-12 22:18:53TaxiradioZárójelekcpp17Wrong answer 0/10025ms1136 KiB
// Source: https://usaco.guide/general/io

#include <bits/stdc++.h>
using namespace std;

array<int , 3> c(string b){
    int x = 0, y = 0 , z = 0;
    for(int i = b.size()-1; i >= 0; i--){
        if(b[i] == '('){
            x--;
            z = min(x , z);
        }else{
            x++;
        }
    }
    x = 0;
    for(int i = 0; i < b.size(); i++){
        if(b[i] == ')'){
            x--;
            y = min(x , y);
        }else{
            x++;
        }
    }
    return {x , y , z};
}

int main() {
	int n; cin >> n;
    vector<array<int , 3>> a , d;
    int k = 0;
    for(int i = 0; i < n; i++){
        string b; cin >> b;
        array<int , 3> o = c(b);
        k += o[0];
        if(o[0] >= 0)a.push_back({o[1] , o[0] , i});else d.push_back({-o[2] , o[0] , i});
    }
    if(k != 0){
        cout << "-1" << endl;
        return 0;
    }
    sort(a.begin() , a.end());
    sort(d.begin() , d.end());
    vector<int> ans1 , ans2;
    int h = 0;
    for(int i = 0; i < a.size(); i++){
        if(a[i][0] <= h){
            ans1.push_back(a[i][2]);
            h += a[i][1];
        }else{
            cout << "-1" << endl;
            return 0;
        }
    }
    h = 0;
    for(int i = 0; i < d.size(); i++){
        if(d[i][0] <= h){
            ans2.push_back(d[i][2]);
            h += d[i][1];
        }else{
            cout << "-1" << endl;
            return 0;
        }
    }
    for(int x : ans1)cout << x+1 << " ";
    reverse(ans2.begin() , ans2.end());
    for(int x : ans2)cout << x+1 << " ";
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted1ms316 KiB
2Wrong answer8ms316 KiB
subtask20/11
3Wrong answer1ms316 KiB
4Wrong answer1ms316 KiB
5Wrong answer1ms316 KiB
6Wrong answer1ms316 KiB
7Wrong answer8ms564 KiB
8Accepted8ms756 KiB
subtask30/6
9Wrong answer7ms316 KiB
10Accepted6ms316 KiB
11Accepted7ms448 KiB
subtask40/14
12Wrong answer7ms316 KiB
13Wrong answer7ms420 KiB
subtask50/23
14Wrong answer7ms316 KiB
15Wrong answer7ms316 KiB
subtask60/19
16Wrong answer8ms428 KiB
17Wrong answer8ms420 KiB
18Wrong answer8ms468 KiB
19Wrong answer7ms452 KiB
20Wrong answer7ms316 KiB
21Wrong answer4ms316 KiB
22Wrong answer4ms316 KiB
23Wrong answer4ms508 KiB
24Wrong answer4ms408 KiB
subtask70/27
25Accepted8ms316 KiB
26Wrong answer8ms316 KiB
27Wrong answer9ms316 KiB
28Wrong answer9ms316 KiB
29Wrong answer13ms708 KiB
30Wrong answer25ms1136 KiB
31Wrong answer8ms500 KiB
32Wrong answer8ms544 KiB
33Wrong answer7ms316 KiB
34Wrong answer8ms316 KiB
35Wrong answer6ms316 KiB
36Wrong answer8ms552 KiB
37Accepted7ms508 KiB
38Wrong answer7ms352 KiB
39Wrong answer14ms736 KiB
40Wrong answer4ms316 KiB
41Wrong answer2ms508 KiB
42Wrong answer6ms408 KiB
43Wrong answer4ms316 KiB