#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 << " ";
}
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1808 KiB | ||||
2 | Accepted | 8ms | 2180 KiB | ||||
subtask2 | 11/11 | ||||||
3 | Accepted | 3ms | 2328 KiB | ||||
4 | Accepted | 3ms | 2540 KiB | ||||
5 | Accepted | 3ms | 2672 KiB | ||||
6 | Accepted | 3ms | 2728 KiB | ||||
7 | Accepted | 7ms | 3228 KiB | ||||
8 | Accepted | 7ms | 3448 KiB | ||||
subtask3 | 6/6 | ||||||
9 | Accepted | 8ms | 3188 KiB | ||||
10 | Accepted | 8ms | 3520 KiB | ||||
11 | Accepted | 8ms | 3472 KiB | ||||
subtask4 | 14/14 | ||||||
12 | Accepted | 8ms | 3672 KiB | ||||
13 | Accepted | 8ms | 3720 KiB | ||||
subtask5 | 23/23 | ||||||
14 | Accepted | 8ms | 3628 KiB | ||||
15 | Accepted | 8ms | 3936 KiB | ||||
subtask6 | 19/19 | ||||||
16 | Accepted | 7ms | 4020 KiB | ||||
17 | Accepted | 8ms | 4076 KiB | ||||
18 | Accepted | 8ms | 4156 KiB | ||||
19 | Accepted | 8ms | 4368 KiB | ||||
20 | Accepted | 8ms | 4328 KiB | ||||
21 | Accepted | 6ms | 4436 KiB | ||||
22 | Accepted | 6ms | 4368 KiB | ||||
23 | Accepted | 6ms | 4644 KiB | ||||
24 | Accepted | 6ms | 4580 KiB | ||||
subtask7 | 27/27 | ||||||
25 | Accepted | 7ms | 4516 KiB | ||||
26 | Accepted | 8ms | 4668 KiB | ||||
27 | Accepted | 8ms | 4676 KiB | ||||
28 | Accepted | 8ms | 4684 KiB | ||||
29 | Accepted | 10ms | 5052 KiB | ||||
30 | Accepted | 25ms | 6820 KiB | ||||
31 | Accepted | 8ms | 4832 KiB | ||||
32 | Accepted | 8ms | 4988 KiB | ||||
33 | Accepted | 8ms | 4676 KiB | ||||
34 | Accepted | 9ms | 4844 KiB | ||||
35 | Accepted | 8ms | 4752 KiB | ||||
36 | Accepted | 9ms | 5088 KiB | ||||
37 | Accepted | 7ms | 4856 KiB | ||||
38 | Accepted | 8ms | 4864 KiB | ||||
39 | Accepted | 14ms | 5748 KiB | ||||
40 | Accepted | 4ms | 4800 KiB | ||||
41 | Accepted | 4ms | 4748 KiB | ||||
42 | Accepted | 7ms | 4992 KiB | ||||
43 | Accepted | 6ms | 4976 KiB |