#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 > b.r;
}
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(), comp);
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 | 0/11 | ||||||
3 | Accepted | 3ms | 2332 KiB | ||||
4 | Wrong answer | 3ms | 2580 KiB | ||||
5 | Wrong answer | 3ms | 2676 KiB | ||||
6 | Accepted | 2ms | 2724 KiB | ||||
7 | Accepted | 8ms | 3348 KiB | ||||
8 | Accepted | 8ms | 3556 KiB | ||||
subtask3 | 6/6 | ||||||
9 | Accepted | 8ms | 3560 KiB | ||||
10 | Accepted | 8ms | 3776 KiB | ||||
11 | Accepted | 8ms | 3876 KiB | ||||
subtask4 | 14/14 | ||||||
12 | Accepted | 8ms | 3740 KiB | ||||
13 | Accepted | 8ms | 3732 KiB | ||||
subtask5 | 0/23 | ||||||
14 | Wrong answer | 8ms | 3812 KiB | ||||
15 | Wrong answer | 8ms | 3700 KiB | ||||
subtask6 | 0/19 | ||||||
16 | Wrong answer | 8ms | 3808 KiB | ||||
17 | Wrong answer | 8ms | 4024 KiB | ||||
18 | Accepted | 8ms | 4376 KiB | ||||
19 | Wrong answer | 8ms | 4268 KiB | ||||
20 | Wrong answer | 8ms | 4532 KiB | ||||
21 | Wrong answer | 6ms | 4640 KiB | ||||
22 | Wrong answer | 6ms | 4512 KiB | ||||
23 | Wrong answer | 6ms | 4512 KiB | ||||
24 | Wrong answer | 6ms | 4512 KiB | ||||
subtask7 | 0/27 | ||||||
25 | Accepted | 8ms | 4588 KiB | ||||
26 | Wrong answer | 8ms | 4576 KiB | ||||
27 | Wrong answer | 8ms | 4612 KiB | ||||
28 | Wrong answer | 8ms | 4624 KiB | ||||
29 | Wrong answer | 9ms | 4968 KiB | ||||
30 | Wrong answer | 17ms | 7012 KiB | ||||
31 | Wrong answer | 8ms | 4968 KiB | ||||
32 | Wrong answer | 8ms | 5008 KiB | ||||
33 | Wrong answer | 8ms | 4932 KiB | ||||
34 | Wrong answer | 8ms | 5092 KiB | ||||
35 | Wrong answer | 8ms | 4968 KiB | ||||
36 | Wrong answer | 9ms | 5128 KiB | ||||
37 | Accepted | 8ms | 4864 KiB | ||||
38 | Wrong answer | 8ms | 4880 KiB | ||||
39 | Wrong answer | 12ms | 5676 KiB | ||||
40 | Wrong answer | 4ms | 4812 KiB | ||||
41 | Wrong answer | 4ms | 4760 KiB | ||||
42 | Wrong answer | 7ms | 4988 KiB | ||||
43 | Wrong answer | 6ms | 4828 KiB |