#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 | 2240 KiB | ||||
subtask2 | 0/11 | ||||||
3 | Accepted | 3ms | 2224 KiB | ||||
4 | Wrong answer | 3ms | 2464 KiB | ||||
5 | Accepted | 3ms | 2680 KiB | ||||
6 | Accepted | 3ms | 2888 KiB | ||||
7 | Accepted | 7ms | 3452 KiB | ||||
8 | Accepted | 7ms | 3416 KiB | ||||
subtask3 | 6/6 | ||||||
9 | Accepted | 8ms | 3196 KiB | ||||
10 | Accepted | 8ms | 3196 KiB | ||||
11 | Accepted | 8ms | 3456 KiB | ||||
subtask4 | 14/14 | ||||||
12 | Accepted | 8ms | 3424 KiB | ||||
13 | Accepted | 8ms | 3412 KiB | ||||
subtask5 | 23/23 | ||||||
14 | Accepted | 8ms | 3552 KiB | ||||
15 | Accepted | 8ms | 3604 KiB | ||||
subtask6 | 0/19 | ||||||
16 | Accepted | 7ms | 3600 KiB | ||||
17 | Accepted | 8ms | 3608 KiB | ||||
18 | Accepted | 8ms | 3972 KiB | ||||
19 | Accepted | 8ms | 3912 KiB | ||||
20 | Accepted | 8ms | 4168 KiB | ||||
21 | Wrong answer | 6ms | 4120 KiB | ||||
22 | Wrong answer | 6ms | 4380 KiB | ||||
23 | Wrong answer | 6ms | 4580 KiB | ||||
24 | Wrong answer | 6ms | 4544 KiB | ||||
subtask7 | 0/27 | ||||||
25 | Accepted | 7ms | 4480 KiB | ||||
26 | Accepted | 8ms | 4484 KiB | ||||
27 | Accepted | 8ms | 4584 KiB | ||||
28 | Accepted | 8ms | 4596 KiB | ||||
29 | Accepted | 10ms | 4944 KiB | ||||
30 | Accepted | 24ms | 6600 KiB | ||||
31 | Accepted | 8ms | 4548 KiB | ||||
32 | Accepted | 8ms | 4708 KiB | ||||
33 | Accepted | 8ms | 4516 KiB | ||||
34 | Accepted | 9ms | 4684 KiB | ||||
35 | Accepted | 8ms | 4468 KiB | ||||
36 | Accepted | 9ms | 4724 KiB | ||||
37 | Accepted | 7ms | 4600 KiB | ||||
38 | Accepted | 8ms | 4620 KiB | ||||
39 | Accepted | 14ms | 5576 KiB | ||||
40 | Wrong answer | 6ms | 4764 KiB | ||||
41 | Wrong answer | 4ms | 4812 KiB | ||||
42 | Wrong answer | 7ms | 4892 KiB | ||||
43 | Wrong answer | 7ms | 4768 KiB |