#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 | 2236 KiB | ||||
subtask2 | 0/11 | ||||||
3 | Accepted | 3ms | 2384 KiB | ||||
4 | Wrong answer | 3ms | 2552 KiB | ||||
5 | Accepted | 3ms | 2656 KiB | ||||
6 | Accepted | 3ms | 2860 KiB | ||||
7 | Accepted | 7ms | 3324 KiB | ||||
8 | Accepted | 8ms | 3552 KiB | ||||
subtask3 | 6/6 | ||||||
9 | Accepted | 8ms | 3556 KiB | ||||
10 | Accepted | 8ms | 3704 KiB | ||||
11 | Accepted | 8ms | 3788 KiB | ||||
subtask4 | 14/14 | ||||||
12 | Accepted | 8ms | 3768 KiB | ||||
13 | Accepted | 8ms | 3668 KiB | ||||
subtask5 | 23/23 | ||||||
14 | Accepted | 8ms | 3744 KiB | ||||
15 | Accepted | 8ms | 3736 KiB | ||||
subtask6 | 0/19 | ||||||
16 | Accepted | 8ms | 3648 KiB | ||||
17 | Accepted | 8ms | 3840 KiB | ||||
18 | Accepted | 8ms | 4200 KiB | ||||
19 | Accepted | 8ms | 4528 KiB | ||||
20 | Accepted | 8ms | 4364 KiB | ||||
21 | Wrong answer | 6ms | 4664 KiB | ||||
22 | Wrong answer | 6ms | 4620 KiB | ||||
23 | Wrong answer | 6ms | 4616 KiB | ||||
24 | Wrong answer | 6ms | 4620 KiB | ||||
subtask7 | 0/27 | ||||||
25 | Accepted | 8ms | 4560 KiB | ||||
26 | Accepted | 8ms | 4668 KiB | ||||
27 | Accepted | 8ms | 4780 KiB | ||||
28 | Accepted | 8ms | 4780 KiB | ||||
29 | Accepted | 12ms | 4968 KiB | ||||
30 | Accepted | 25ms | 6892 KiB | ||||
31 | Accepted | 8ms | 4944 KiB | ||||
32 | Accepted | 9ms | 5012 KiB | ||||
33 | Accepted | 8ms | 4824 KiB | ||||
34 | Accepted | 9ms | 4996 KiB | ||||
35 | Accepted | 8ms | 4872 KiB | ||||
36 | Accepted | 9ms | 5036 KiB | ||||
37 | Accepted | 8ms | 4784 KiB | ||||
38 | Accepted | 8ms | 4796 KiB | ||||
39 | Accepted | 14ms | 5676 KiB | ||||
40 | Wrong answer | 4ms | 4816 KiB | ||||
41 | Wrong answer | 4ms | 4944 KiB | ||||
42 | Wrong answer | 7ms | 5252 KiB | ||||
43 | Wrong answer | 6ms | 5188 KiB |