167762025-05-12 22:22:23TaxiradioZá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
1Accepted1ms332 KiB
2Wrong answer8ms316 KiB
subtask20/11
3Wrong answer1ms316 KiB
4Wrong answer1ms316 KiB
5Wrong answer1ms316 KiB
6Accepted1ms316 KiB
7Accepted8ms568 KiB
8Accepted8ms564 KiB
subtask30/6
9Wrong answer7ms316 KiB
10Accepted7ms620 KiB
11Accepted7ms508 KiB
subtask40/14
12Wrong answer7ms456 KiB
13Wrong answer7ms316 KiB
subtask50/23
14Wrong answer7ms316 KiB
15Wrong answer7ms508 KiB
subtask60/19
16Wrong answer8ms508 KiB
17Wrong answer8ms316 KiB
18Wrong answer8ms316 KiB
19Wrong answer7ms412 KiB
20Wrong answer7ms316 KiB
21Wrong answer4ms444 KiB
22Wrong answer4ms444 KiB
23Wrong answer4ms412 KiB
24Wrong answer4ms508 KiB
subtask70/27
25Accepted8ms316 KiB
26Wrong answer8ms500 KiB
27Wrong answer9ms500 KiB
28Wrong answer9ms316 KiB
29Wrong answer13ms564 KiB
30Wrong answer25ms1136 KiB
31Wrong answer8ms316 KiB
32Wrong answer8ms316 KiB
33Wrong answer7ms332 KiB
34Wrong answer8ms508 KiB
35Wrong answer6ms316 KiB
36Wrong answer8ms316 KiB
37Accepted6ms316 KiB
38Wrong answer7ms452 KiB
39Wrong answer14ms828 KiB
40Wrong answer4ms316 KiB
41Wrong answer2ms316 KiB
42Wrong answer6ms316 KiB
43Wrong answer4ms424 KiB